home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / go / prog / sungo.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1993-06-20  |  102.8 KB  |  3,885 lines

  1. #! /bin/sh
  2. # This is a shell archive.  Remove anything before this line, then unpack
  3. # it by saving it into a file and typing "sh file".  To overwrite existing
  4. # files, type "sh file -c".  You can also feed this as standard input via
  5. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  6. # will see the following message at the end:
  7. #        "End of shell archive."
  8. # Contents:  Makefile Readme.goban goban.c goban.h goban.icon goboard.c
  9. #   gocapture.c gocircle.c gomaster.c gopanel.c goprint.c goservice.c
  10. #   masterofgo masterofgo.brd
  11. # Wrapped by mariano@poincare on Fri Sep  6 15:07:03 1991
  12. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  13. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  14.   echo shar: Will not clobber existing file \"'Makefile'\"
  15. else
  16. echo shar: Extracting \"'Makefile'\" \(484 characters\)
  17. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  18. X#
  19. X# @(#)Makefile.src.release 1.5 87/10/19 SMI
  20. X#
  21. X
  22. X
  23. XGOBANSRC=     goban.c goboard.c gopanel.c goservice.c gocapture.c gocircle.c \
  24. X    goprint.c gomaster.c
  25. XGOBANOBJ=     goban.o goboard.o gopanel.o goservice.o gocapture.o gocircle.o \
  26. X    goprint.o gomaster.o
  27. X
  28. XWINLIBS=-lsuntool -lsunwindow -lpixrect
  29. X
  30. XFLOATFLAG= -fsingle -fswitch
  31. XCFLAGS = -O $(FLOATFLAG)
  32. X
  33. Xall:    goban
  34. X
  35. Xgoban:  ${GOBANOBJ}
  36. X    cc -o goban ${CFLAGS} ${GOBANOBJ} ${WINLIBS}
  37. X
  38. X${GOBANOBJ}:  goban.icon goban.h
  39. X    cc -c ${CFLAGS} $*.c
  40. X
  41. END_OF_FILE
  42. if test 484 -ne `wc -c <'Makefile'`; then
  43.     echo shar: \"'Makefile'\" unpacked with wrong size!
  44. fi
  45. # end of 'Makefile'
  46. fi
  47. if test -f 'Readme.goban' -a "${1}" != "-c" ; then 
  48.   echo shar: Will not clobber existing file \"'Readme.goban'\"
  49. else
  50. echo shar: Extracting \"'Readme.goban'\" \(5419 characters\)
  51. sed "s/^X//" >'Readme.goban' <<'END_OF_FILE'
  52. Xgoban [name]
  53. X
  54. XFeatures
  55. X    - save and restore games.
  56. X    - step forwards and backwards in moves of a game.
  57. X    - automatic capture of stones.
  58. X    - detects ko violations and suicide moves (illegal).
  59. X    - laserwriter output for board diagrams.
  60. X    - confirmation required for irrevocable actions
  61. X    - dynamic resizing of tool window
  62. X    - automatic handicap placement for 19 x 19 board (up to
  63. X      17 stones).
  64. X    - can start games with placed stones for go problems.
  65. X    - default game from "Master of Go" by Kawabata.
  66. X
  67. XDescription
  68. X
  69. XGoban is Japanese for "go board".  It is an automatic board, but
  70. Xdoes not play go.  If you invoke it with no arguments it will
  71. Xinitialize itself with the game described in the book "The
  72. XMaster of Go", by Yasunari Kawabata, winner of the Nobel Prize
  73. Xfor Literature.  If you give it an argument, it will use that as
  74. Xa base to construct names for files of which there are two
  75. X(assume "name" is the argument):  "name.game" and "name.brd".
  76. X"name.game" is read and written by goban, and is the record of
  77. Xthe game, including handicaps and initial positions of stones
  78. X(for go problems).   "name.brd" is written only and is an ascii
  79. Xrepresentation of the board and the moves, suitable for
  80. Xelectronic mailing.
  81. X
  82. XThere are four windows.  The two wide ones at the top of the
  83. Xtool are for messages.  The lower part of goban consists of a
  84. Xboard diagram and a control panel.
  85. X
  86. XThe top window explains what actions the mouse buttons perform
  87. Xat a given moment.  When confirmation of a command is required
  88. Xthe message will say "Confirm:  right mouse button.  Deny:  Left
  89. Xand center buttons."  The second window displays the number of
  90. Xcaptured stones.
  91. X
  92. XStones are placed on the board by selecting the grid point with
  93. Xthe cursor and pressing the left button.  In the control panel
  94. Xthe color of the stone of the player to play next ("Next:") will
  95. Xchange.  If the center button is pressed in the board area,
  96. Xgoban will backup a move (undo it).  The right button causes
  97. Xgoban to move forward in the game.  Stepping backwards and
  98. Xforwards will not alter the game until the left button is
  99. Xpressed to place a stone.  Then any moves beyond the current
  100. Xposition will be discarded.
  101. X
  102. XThe control panel provides the following controls:
  103. X
  104. XMoving (Placing):  Pressing this button changes the state from
  105. Xmaking moves to placing stones or vice versa.  The current state
  106. Xis indicated.  If stones are being "placed" then the color of
  107. Xthe next stone to be placed will not change unless the stone
  108. Xbeside the label "Next:" (or the label) is hit with the left
  109. Xmouse button.  Placing stones should be done only after a
  110. X"Reset" has been issued (see "Reset") (but this is not
  111. Xenforced).
  112. X
  113. XPass:  The "pass" move is made (no stone is placed) and it is
  114. Xthe next player's turn.
  115. X
  116. XReplay:  Redraws the board.
  117. X
  118. XClose:  Closes goban to iconic state.
  119. X
  120. XQuit:  Exit the goban program.  Must be confirmed with right mouse
  121. Xbutton.
  122. X
  123. XReset:  Reset the state of the game to it's initial state which
  124. Xis that no moves have been made, but the handicap stones are on
  125. Xthe board.  (See "Handicap").  Must be confirmed with right
  126. Xmouse button.
  127. X
  128. XCurrent Move (Slider):  Replay the game to the move number
  129. Xcontrolled by the slider when the mouse button is released.
  130. X
  131. XHandicap (Slider):  Control the number of handicap stones that
  132. Xwill be automatically placed if "Reset" is issued.
  133. X
  134. XGame:  Type in and change the name that is used to form the file
  135. Xnames used to save the game record and the ascii board
  136. Xrepresentation.  ("name.game" and "name.brd").
  137. X
  138. XRead Game:  Read in a new game record (if the "Game:" name has
  139. Xbeen changed) or reread the current game record from
  140. X"name.game".  Must be confirmed with right mouse button.
  141. X
  142. XPrint:  Goban will send PostScript commands to the printer in
  143. Xthe system that goes by the tag "Plw" (normally the default Sun
  144. Xlaser writer).  A diagram of the board will be printed.
  145. X
  146. XWrite Game:  Write the current state of the game to "name.game"
  147. Xwhere "name" is the value of the "Game:" panel button.  Must be
  148. Xconfirmed with right mouse button.
  149. X
  150. XWrite Board:  Write an ascii representation of the board and the
  151. Xmoves to "name.brd" where "name" is the value of the "Game:"
  152. Xpanel button.  Must be confirmed with right mouse button.
  153. X
  154. X
  155. X
  156. XSample ".game" File (19x19 board, no handicap)
  157. X
  158. X19
  159. X0
  160. X .
  161. X .
  162. XBlack
  163. X D3 Q16
  164. X R4 C16
  165. X C10 Q3
  166. X R3 M3
  167. X K16 G16
  168. X N16 R10
  169. X R8 C6
  170. X C7 C3
  171. X C4 E3
  172. X B3
  173. X
  174. X
  175. XSample ".brd" File (19x19 board, no handicap)
  176. X
  177. X   A B C D E F G H J K L M N O P Q R S T
  178. X19 . . . . . . . . . . . . . . . . . . . 19
  179. X18 . . . . . . . . . . . . . . . . . . . 18
  180. X17 . . . . . . . . . . . . . . . . . . . 17
  181. X16 . . O . . . O . . * . . * . . O . . . 16
  182. X15 . . . . . . . . . . . . . . . . . . . 15
  183. X14 . . . . . . . . . . . . . . . . . . . 14
  184. X13 . . . . . . . . . . . . . . . . . . . 13
  185. X12 . . . . . . . . . . . . . . . . . . . 12
  186. X11 . . . . . . . . . . . . . . . . . . . 11
  187. X10 . . * . . . . . . . . . . . . . O . . 10
  188. X 9 . . . . . . . . . . . . . . . . . . .  9
  189. X 8 . . . . . . . . . . . . . . . . * . .  8
  190. X 7 . . * . . . . . . . . . . . . . . . .  7
  191. X 6 . . O . . . . . . . . . . . . . . . .  6
  192. X 5 . . . . . . . . . . . . . . . . . . .  5
  193. X 4 . . * . . . . . . . . . . . . . * . .  4
  194. X 3 . * O * O . . . . . . O . . . O * . .  3
  195. X 2 . . . . . . . . . . . . . . . . . . .  2
  196. X 1 . . . . . . . . . . . . . . . . . . .  1
  197. X   A B C D E F G H J K L M N O P Q R S T
  198. X  1:    D3    Q16.
  199. X  3:    R4    C16.
  200. X  5:    C10    Q3.
  201. X  7:    R3    M3.
  202. X  9:    K16    G16.
  203. X 11:    N16    R10.
  204. X 13:    R8    C6.
  205. X 15:    C7    C3.
  206. X 17:    C4    E3.
  207. X 19:    B3
  208. X
  209. END_OF_FILE
  210. if test 5419 -ne `wc -c <'Readme.goban'`; then
  211.     echo shar: \"'Readme.goban'\" unpacked with wrong size!
  212. fi
  213. # end of 'Readme.goban'
  214. fi
  215. if test -f 'goban.c' -a "${1}" != "-c" ; then 
  216.   echo shar: Will not clobber existing file \"'goban.c'\"
  217. else
  218. echo shar: Extracting \"'goban.c'\" \(8350 characters\)
  219. sed "s/^X//" >'goban.c' <<'END_OF_FILE'
  220. X#ifndef lint
  221. Xstatic char sccsid[]= "@(#)goban.c 1.3 87/01/11 Copyr 1986 Sun Micro";
  222. X#endif
  223. X
  224. X/* Copyright (c) Sun MicroSystems, 1986.  This code may be used and modified
  225. X    for not-for-profit use.  This notice must be retained.  */
  226. X
  227. X#include "goban.h"
  228. X#include <suntool/panel.h>
  229. X#include <suntool/canvas.h>
  230. X#include <suntool/textsw.h>
  231. X
  232. X
  233. Xstatic short IconBits [] = {
  234. X#include "goban.icon"
  235. X};
  236. XDEFINE_ICON_FROM_IMAGE (GobanIcon, IconBits);
  237. X
  238. X
  239. Xint        RootFD;
  240. XFrame        GoFrame;
  241. XCanvas        BoardSW;
  242. XPixwin        *BoardPW;
  243. Xstruct pixrect    *BlackStone, *WhiteStone, *BlackFirstImage, *WhiteFirstImage;
  244. Xstruct pixfont    *Font, *Fonts [4];
  245. XPanel        MainPanel;
  246. XPanel        MsgSW, StatusSW;
  247. XPanel_item    CurrMoveSlider, HandicapSlider, FirstPlayerButton;
  248. XPanel_item    PlaceMoveButton, NameButton, LabelButton;
  249. XPanel_item    MsgPanelItem, StatusPanelItem;
  250. XTextsw        TextSW;
  251. Xint        (*CachedTextSWProc) ();
  252. Xint        UserTextMods, Verbose;
  253. X
  254. Xint RemBSWWidth, RemBSWHeight;
  255. Xint Radius;
  256. Xint LineWidth;
  257. Xint DebugLevel;
  258. Xint Checked [MaxGrid] [MaxGrid];    /* Initialized to zero. */
  259. Xint CheckNum;                /* Initialized to 1. */
  260. X
  261. Xchar    GameName [80] = " ";
  262. X
  263. X
  264. X/* Forward declarations. */
  265. XBSWEventProc ();
  266. XBSWRepaintProc ();
  267. XBSWResizeProc ();
  268. XMoveType    *IsAltOfNextMove ();
  269. XTextSWProc ();
  270. X
  271. Xextern SigPipe ();
  272. X
  273. X
  274. Xmain (argc, argv)
  275. X    int argc;
  276. X    char *argv [];
  277. X{
  278. XGameType    *Game;
  279. Xint i, j;
  280. X    for (i= 0; i < MaxGrid; i++)
  281. X    for (j= 0; j < MaxGrid; j++)
  282. X        Checked [i][j]= 0;
  283. X    CheckNum= 1;
  284. X    Game= Malloc (GameType);
  285. X    Hello (&argc, argv, Game);
  286. X    if (GameName [0] == ' ') {
  287. X    DfltGame (GameName, Game, PANEL_CLEAR);
  288. X    } else {
  289. X    if (ReadGame (GameName, Game, PANEL_CLEAR)) {
  290. X        fprintf (stderr, "Unable to read \"%s\".\n", GameName);
  291. X        ZeroGame (Game, PANEL_CLEAR);
  292. X        HandicapBoard (Game);
  293. X    }
  294. X    }
  295. X    window_main_loop (GoFrame);
  296. X} /* main */
  297. X
  298. X
  299. XBSWEventProc (canvas, event)
  300. X    Canvas    canvas;
  301. X    Event    *event;
  302. X{
  303. Xint        i, j, k;
  304. XGameType    *Game;
  305. XMoveType    *Move;
  306. X    if (event_is_up (event)) return;
  307. X    Game= (GameType *) window_get (BoardSW, WIN_CLIENT_DATA);
  308. X    if (UserTextMods) SaveText (Game);
  309. X    switch (event_id (event)) {
  310. X    case '\003':
  311. X    exit (0); break;
  312. X    case MS_LEFT:
  313. X    i= (event_x (event) - 5 - 4 * Radius) / (2 * Radius);
  314. X    j= Game->Grid - 1 - (event_y (event) - 5 - 4 * Radius) / (2 * Radius);
  315. X    if (event_ctrl_is_down (event))
  316. X        EnterMove (i, j, Game, 1, MoveAction);
  317. X    else if (Move= IsAltOfNextMove (Game->CurrMove, i, j)) {
  318. X        if (Game->CurrMove->Next != Move) {
  319. X        PanelToLabel (Game->CurrMove->Next);
  320. X        Game->CurrMove->Next= Move;
  321. X        for (k= Game->MoveNum; Move->Next != NULL; Move= Move->Next)
  322. X            k++;
  323. X        panel_set (CurrMoveSlider, PANEL_MAX_VALUE, k, 0);
  324. X        LabelToPanel (Game->CurrMove->Next);
  325. X        }
  326. X        Step (Game, 1);
  327. X    } else EnterMove (i, j, Game, 1, AltMoveAction);
  328. X    break;
  329. X    case MS_MIDDLE:
  330. X    if (Game->Placing) {
  331. X        i= (event_x (event) - 5 - 4 * Radius) / (2 * Radius);
  332. X        j= Game->Grid - 1 - (event_y(event) - 5 - 4 * Radius) / (2*Radius);
  333. X        Game->Board [i][j]= Game->InitialBoard [i][j]= Empty;
  334. X        DrawEmpty (Game, i, j);
  335. X    } else
  336. X        Backup (Game, 1);
  337. X    break;
  338. X    case MS_RIGHT:
  339. X    if (event_ctrl_is_down (event)) Sideways (Game, 1);
  340. X    else Step (Game, 1);
  341. X    break;
  342. X    }
  343. X} /* BSWEventProc */
  344. X
  345. X
  346. XBSWRepaintProc (canvas, pw, RepaintRects)
  347. X    Canvas    canvas;
  348. X    Pixwin    *pw;
  349. X    Rectlist    RepaintRects;
  350. X{
  351. XGameType    *Game;
  352. Xint        Width, Height;
  353. X    Width= (int) window_get (canvas, CANVAS_WIDTH);
  354. X    Height= (int) window_get (canvas, CANVAS_HEIGHT);
  355. X    Game= (GameType *) window_get (BoardSW, WIN_CLIENT_DATA);
  356. X    pw_writebackground (BoardPW, 0, 0, Width, Height, PIX_CLR);
  357. X    DrawGame (Game, 1);
  358. X} /* BSWRepaintProc */
  359. X
  360. X
  361. XBSWResizeProc (canvas, Width, Height)
  362. X    Canvas canvas;
  363. X    int Width, Height;
  364. X{
  365. Xstruct rect *r;
  366. XGameType *Game= (GameType *) window_get (BoardSW, WIN_CLIENT_DATA);
  367. X    DrawGameInit (Game, Width, Height);
  368. X} /* BSWResizeProc */
  369. X
  370. X
  371. XHello (argc, argv, Game)
  372. X    int *argc;
  373. X    char *argv [];
  374. X    GameType *Game;
  375. X{
  376. Xchar    FrameName [80];
  377. Xchar    *c, *g;
  378. X    Verbose= 1;
  379. X    strncpy (FrameName, argv [0], 75);
  380. X    strcat (FrameName, ".3.2");
  381. X    GoFrame= window_create (NULL, FRAME,
  382. X    FRAME_ICON,        &GobanIcon,
  383. X    FRAME_ARGC_PTR_ARGV,    argc, argv,
  384. X    FRAME_LABEL,        FrameName,
  385. X    WIN_HEIGHT,        900,
  386. X    WIN_Y,            0,
  387. X    0);
  388. X    while (--(*argc) > 0) {
  389. X        if ('-' == (*++argv) [0]) {
  390. X            switch ((*argv) [1]) {
  391. X        case 'd':
  392. X                c= &((*argv) [2]);
  393. X        if (*c == '\0') {
  394. X            --(*argc);
  395. X            c= &((*++argv) [0]);
  396. X        }
  397. X        DebugLevel= atoi (c);
  398. X        break;
  399. X            case 'g':
  400. X                break;
  401. X            } /* switch */
  402. X        } else {
  403. X        c= &((*argv) [0]);
  404. X        g= GameName;
  405. X        do {
  406. X        *g++= *c;
  407. X        } while (*c++ != '\0');
  408. X    } /* else */
  409. X    } /* while */
  410. X    Font= pw_pfsysopen ();
  411. X    InitSW (GoFrame, Game);
  412. X    Fonts [0]= pf_open ("/usr/lib/fonts/fixedwidthfonts/screen.r.7");
  413. X    if (Fonts [0] == NULL)
  414. X    fprintf (stderr
  415. X        , "Can't open \"/usr/lib/fonts/fixedwidthfonts/screen.r.7\".\n");
  416. X    Fonts [1]= pf_open ("/usr/lib/fonts/fixedwidthfonts/screen.r.11");
  417. X    if (Fonts [1] == NULL)
  418. X    fprintf (stderr
  419. X        , "Can't open \"/usr/lib/fonts/fixedwidthfonts/screen.r.11\".\n");
  420. X    Fonts [2]= pf_open ("/usr/lib/fonts/fixedwidthfonts/screen.r.14");
  421. X    if (Fonts [2] == NULL)
  422. X    fprintf (stderr
  423. X        , "Can't open \"/usr/lib/fonts/fixedwidthfonts/screen.r.14\".\n");
  424. X    Fonts [3]= pf_open ("/usr/lib/fonts/fixedwidthfonts/gallant.r.19");
  425. X    if (Fonts [3] == NULL)
  426. X    fprintf (stderr
  427. X        , "Can't open \"/usr/lib/fonts/fixedwidthfonts/gallant.r.19\".\n");
  428. X    RootFD= (int) window_get (GoFrame, WIN_FD);
  429. X    signal (SIGPIPE, SigPipe);
  430. X} /* Hello */
  431. X
  432. X
  433. XInitSW (GoFrame, Game)
  434. X    Frame    GoFrame;
  435. X    GameType    *Game;
  436. X/* Initialize board subwindow. */
  437. X{
  438. Xstruct inputmask Mask;
  439. Xint Width;    /* Assume square. */
  440. X    MsgSW= (Panel) window_create (GoFrame, PANEL,
  441. X    WIN_HEIGHT,        MsgSWHeight,
  442. X    0);
  443. X    StatusSW= (Panel) window_create (GoFrame, PANEL,
  444. X    WIN_HEIGHT,        StatusSWHeight,
  445. X    0);
  446. X    MainPanel= window_create (GoFrame, PANEL, 0);
  447. X    InitPanel (Game, GameName, MsgSW, StatusSW);
  448. X    window_fit (MainPanel);
  449. X    Width= ((struct rect *) window_get (GoFrame, FRAME_OPEN_RECT))->r_width;
  450. X    BoardSW= window_create (GoFrame, CANVAS,
  451. X    WIN_WIDTH,        Width - 10,
  452. X    WIN_HEIGHT,        Width - 10,
  453. X    CANVAS_WIDTH,        Width - 10,
  454. X    CANVAS_HEIGHT,        Width - 10,
  455. X    WIN_BELOW,        MainPanel,
  456. X    WIN_X,            0,
  457. X    WIN_CLIENT_DATA,    Game,
  458. X    WIN_EVENT_PROC,        BSWEventProc,
  459. X    WIN_CONSUME_PICK_EVENTS, WIN_NO_EVENTS, WIN_MOUSE_BUTTONS, 0,
  460. X    WIN_CONSUME_KBD_EVENTS,    WIN_NO_EVENTS, WIN_ASCII_EVENTS, 0,
  461. X    CANVAS_RESIZE_PROC,    BSWResizeProc,
  462. X    CANVAS_REPAINT_PROC,    BSWRepaintProc,
  463. X    CANVAS_RETAINED,    FALSE,
  464. X    CANVAS_FIXED_IMAGE,    FALSE,
  465. X    0);
  466. X    if (BoardSW == NULL)
  467. X    Cafard ("Couldn't create BSW subwindow");
  468. X    BoardPW = (Pixwin *) window_get (BoardSW, WIN_PIXWIN);
  469. X    if (BoardPW == (struct pixwin *) NULL)
  470. X    Cafard ("Couldn't create BSW pixwin");
  471. X    TextSW= window_create (GoFrame, TEXTSW,
  472. X    WIN_BELOW,    BoardSW,
  473. X    WIN_X,        0,
  474. X    0);
  475. X    CachedTextSWProc= (int (*) ()) window_get (TextSW, TEXTSW_NOTIFY_PROC);
  476. X    window_set (TextSW, TEXTSW_NOTIFY_PROC, TextSWProc, 0);
  477. X    window_set (TextSW, TEXTSW_NOTIFY_LEVEL
  478. X    , TEXTSW_NOTIFY_STANDARD | TEXTSW_NOTIFY_EDIT, 0);
  479. X} /* InitSW */
  480. X
  481. X
  482. X    MoveType *
  483. XIsAltOfNextMove (m, i, j)
  484. X    MoveType *m;
  485. X    int    i, j;
  486. X{
  487. XMoveType *m1;
  488. X    if (m == NULL) return 0;
  489. X    for (m1= m->Next; m1 != NULL; ) {
  490. X    if ((m1->i == i) && (m1->j == j)) return m1;
  491. X    m1= m1->AltNext;
  492. X    if (m1 == m->Next) return 0;
  493. X    }
  494. X    return 0;
  495. X} /* IsAltOfNextMove */
  496. X
  497. X
  498. XSaveText (Game)
  499. X    GameType *Game;
  500. X{
  501. X    if (Game != NULL) {
  502. X    if (Game->CurrMove == NULL) {
  503. X        TextSWToData (&(Game->Note));
  504. X    } else {
  505. X        TextSWToData (&(Game->CurrMove->Note));
  506. X    }
  507. X    UserTextMods= 0;
  508. X    }
  509. X} /* SaveText */
  510. X
  511. X
  512. XTextSWProc (textsw, attributes)
  513. X    Textsw    textsw;
  514. X    Attr_avlist    attributes;
  515. X{
  516. XAttr_avlist    attrs;
  517. X    for (attrs= attributes; *attrs; attrs= attr_next (attrs)) {
  518. X    UserTextMods++;
  519. X    }
  520. X    CachedTextSWProc (textsw, attributes);
  521. X} /* TextSWProc */
  522. X
  523. X
  524. XTextSWToData (StringPtrPtr)
  525. X    char    **StringPtrPtr;
  526. X{
  527. Xchar    *s;
  528. Xint Length;
  529. X    if (*StringPtrPtr != NULL) {
  530. X    free (*StringPtrPtr);
  531. X    *StringPtrPtr= NULL;
  532. X    }
  533. X    Length= (int) window_get (TextSW, TEXTSW_LENGTH);
  534. X    if (Length != 0) {
  535. X    s= *StringPtrPtr= (char *) malloc (Length);
  536. X    window_get (TextSW, TEXTSW_CONTENTS, 0, s, Length - 1);
  537. X        /* Ignore added last newline character. */
  538. X    s [Length - 1]= '\0';
  539. X    }
  540. X} /* TextSWToData */
  541. END_OF_FILE
  542. if test 8350 -ne `wc -c <'goban.c'`; then
  543.     echo shar: \"'goban.c'\" unpacked with wrong size!
  544. fi
  545. # end of 'goban.c'
  546. fi
  547. if test -f 'goban.h' -a "${1}" != "-c" ; then 
  548.   echo shar: Will not clobber existing file \"'goban.h'\"
  549. else
  550. echo shar: Extracting \"'goban.h'\" \(2583 characters\)
  551. sed "s/^X//" >'goban.h' <<'END_OF_FILE'
  552. X/* @(#)goban.h 1.3 87/01/11 Copyr 1986 Sun Micro
  553. X    Copyright (c) Sun MicroSystems, 1986.  This code may be used and modified
  554. X    for not-for-profit use.  This notice must be retained.  */
  555. X
  556. X#include <suntool/sunview.h>
  557. X#include <stdio.h>
  558. X#include <sys/file.h>
  559. X
  560. X#define Black    0
  561. X#define White    1
  562. X    /* White == !Black. */
  563. X#define Empty    2
  564. X
  565. X/* Actions */
  566. X#define MoveAction    1
  567. X#define    PassAction    2
  568. X#define AltMoveAction    3
  569. X
  570. X#define NoDir    0
  571. X#define North    (1 << 1)
  572. X#define East    (1 << 2)
  573. X#define South    (1 << 3)
  574. X#define West    (1 << 4)
  575. X
  576. X#define MsgSWHeight     25
  577. X#define StatusSWHeight     25
  578. X
  579. X#define MaxGrid        21
  580. X#define MaxHandicap    17
  581. X#define MaxMoves    ((MaxGrid * MaxGrid * 3) / 2)
  582. X#define MaxTitleChars    40
  583. X#define MaxMvLblChars    2
  584. X
  585. X#define Malloc(a)    (a *) malloc (sizeof (a))
  586. X
  587. Xtypedef short Stone;
  588. X
  589. Xtypedef struct MoveType {
  590. X    char i, j;            /* i == -1 means pass. */
  591. X    struct CaptureType *Captures;
  592. X    struct MoveType *Next, *Prev, *AltNext, *AltPrev;
  593. X    char *Note;
  594. X    char Label [MaxMvLblChars];
  595. X} MoveType;
  596. X
  597. Xtypedef struct CaptureType {
  598. X    unsigned char i, j;
  599. X    struct CaptureType *Next;
  600. X} CaptureType;
  601. X
  602. Xtypedef struct GroupType {
  603. X    short Color;
  604. X    short NumLibs;
  605. X    short NumStones;
  606. X    struct GroupType *Next;    /* for Trash list only. */
  607. X} GroupType;
  608. X
  609. Xtypedef struct GameType {
  610. X    char Title [40];    /* keyword of filenames Title.brd and Title.game. */
  611. X    char *Note;
  612. X    Stone Board [MaxGrid] [MaxGrid];
  613. X    Stone InitialBoard [MaxGrid] [MaxGrid];
  614. X    GroupType *Groups [MaxGrid] [MaxGrid];
  615. X    MoveType *MoveList, *CurrMove;
  616. X    short NumMoves;        /* Gets set to MoveNum if player changes play.*/
  617. X    short MoveNum;        /* Initially NumMoves. */
  618. X    short Handicap;
  619. X    short Prisoners [2];    /* Prisoner stones colored with given color. */
  620. X    Stone FirstPlayer;        /* Black or White. */
  621. X    short Placing;        /* 1 if user placing stones (not yet moving)*/
  622. X    short Grid;
  623. X    /* Size of board:  9 (neophyte), 13 (novice), 17 (historical),
  624. X        19 (standard), 21 (experimental). */
  625. X} GameType;
  626. X
  627. Xextern MoveType        *TrashMoves;
  628. Xextern CaptureType    *TrashCaptures;
  629. Xextern GroupType    *TrashGroups;
  630. X
  631. Xextern struct screen    Screen;
  632. Xextern int        RootFD;
  633. Xextern Frame        GoFrame;
  634. Xextern Pixwin        *BoardPW;
  635. Xextern struct pixrect    *BlackStone, *WhiteStone;
  636. Xextern struct pixrect    *BlackFirstImage, *WhiteFirstImage;
  637. Xextern struct pixfont    *Font, *Fonts [4];
  638. X
  639. Xextern int RemBSWWidth, RemBSWHeight;
  640. Xextern int Radius, LineWidth;
  641. Xextern int DebugLevel;
  642. Xextern int Checked [MaxGrid][MaxGrid];
  643. Xextern int CheckNum;
  644. X
  645. Xextern MoveType     *AllocMove ();
  646. Xextern CaptureType    *AllocCapture ();
  647. Xextern GroupType    *AllocGroup ();
  648. END_OF_FILE
  649. if test 2583 -ne `wc -c <'goban.h'`; then
  650.     echo shar: \"'goban.h'\" unpacked with wrong size!
  651. fi
  652. # end of 'goban.h'
  653. fi
  654. if test -f 'goban.icon' -a "${1}" != "-c" ; then 
  655.   echo shar: Will not clobber existing file \"'goban.icon'\"
  656. else
  657. echo shar: Extracting \"'goban.icon'\" \(1933 characters\)
  658. sed "s/^X//" >'goban.icon' <<'END_OF_FILE'
  659. X/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
  660. X */
  661. X    0xF888,0x8C8A,0x8988,0x88CF,0xF22A,0x2622,0x27E2,0xA26E,
  662. X    0xF44C,0x4446,0x4FE4,0xC44F,0xF119,0x1513,0x1FF1,0x915B,
  663. X    0xF888,0x8C8A,0x9FF8,0x88CF,0xFFFF,0xFFFF,0xFFFF,0xFFEE,
  664. X    0xF44C,0x4446,0x5FF4,0xC44F,0xF119,0x1513,0x1FF1,0x915B,
  665. X    0xF888,0x8C8A,0x8FE8,0x88CF,0xF22A,0x2622,0x27E2,0xA26E,
  666. X    0xF44C,0x4446,0x47C4,0xC44F,0xF119,0x1512,0x1FF1,0x915B,
  667. X    0xF888,0x8C87,0x1FF8,0x88CF,0xF22A,0x262F,0xBFF2,0xA26E,
  668. X    0xFFFF,0xFFFF,0xFFFF,0xFFCF,0xF119,0x150F,0x9FF1,0x915B,
  669. X    0xF888,0x8C87,0x1FF8,0x88CF,0xF22A,0x2622,0x2FE2,0xA26E,
  670. X    0xF44C,0x4446,0x47C4,0xC44F,0xF119,0x1F1F,0x97D3,0xF15B,
  671. X    0xF888,0xBF9F,0xCC6E,0x38CF,0xF22A,0x7FFF,0xF83C,0x1A6E,
  672. X    0xF44C,0x7FFF,0xF018,0x0C4F,0xFFFF,0xFFFF,0xF018,0x0FDB,
  673. X    0xF888,0xFFFF,0xF018,0x08CF,0xF22A,0x7FFF,0xF83C,0x1A6E,
  674. X    0xF44C,0x7FFF,0xEC66,0x344F,0xF119,0x1F1F,0xD7D3,0xF15B,
  675. X    0xF888,0x8C8F,0x8988,0x88CF,0xF22A,0x2638,0xE322,0xA26E,
  676. X    0xF44C,0x4470,0x6544,0xC44F,0xF119,0x1520,0x3111,0x915B,
  677. X    0xFFFF,0xFFE0,0x3FFF,0xFFCF,0xF22A,0x2620,0x2322,0xA26E,
  678. X    0xF44C,0x4470,0x6544,0xC44F,0xF119,0x1518,0xD111,0x915B,
  679. X    0xF888,0x8C8F,0x8988,0x88CF,0xF22A,0x2622,0x2322,0xA26E,
  680. X    0xF44C,0x4446,0x4544,0xC44F,0xF119,0x1513,0x1111,0x915B,
  681. X    0xF888,0x8C8A,0x8988,0x88CF,0xFFFF,0xFFFF,0xFFFF,0xFFEE,
  682. X    0xF444,0x4444,0x4444,0x444F,0xF111,0x1111,0x1111,0x111B,
  683. X    0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFEEE,0xEEEE,0xEEEE,0xEEEE,
  684. X    0xF7FF,0xFFFF,0xFFFF,0xFFFF,0xF3BB,0xBBBB,0xBBBB,0xBBBB,
  685. X    0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001,
  686. X    0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001,
  687. X    0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001,
  688. X    0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001,
  689. X    0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001,
  690. X    0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001,
  691. X    0x8000,0x0000,0x0000,0x0001,0x8000,0x0000,0x0000,0x0001,
  692. X    0x8000,0x0000,0x0000,0x0001,0xFFFF,0xFFFF,0xFFFF,0xFFFF
  693. END_OF_FILE
  694. if test 1933 -ne `wc -c <'goban.icon'`; then
  695.     echo shar: \"'goban.icon'\" unpacked with wrong size!
  696. fi
  697. # end of 'goban.icon'
  698. fi
  699. if test -f 'goboard.c' -a "${1}" != "-c" ; then 
  700.   echo shar: Will not clobber existing file \"'goboard.c'\"
  701. else
  702. echo shar: Extracting \"'goboard.c'\" \(15937 characters\)
  703. sed "s/^X//" >'goboard.c' <<'END_OF_FILE'
  704. X#ifndef lint
  705. Xstatic char sccsid[]= "@(#)goboard.c 1.3 87/01/11 Copyr 1986 Sun Micro";
  706. X#endif
  707. X
  708. X/* Copyright (c) Sun MicroSystems, 1986.  This code may be used and modified
  709. X    for not-for-profit use.  This notice must be retained.  */
  710. X
  711. X#include "goban.h"
  712. X#include <suntool/canvas.h>
  713. X#include <suntool/panel.h>
  714. X#include <suntool/textsw.h>
  715. X
  716. X
  717. X#define GridX(i)    (5 + Radius + ((i) + 2) * 2 * Radius)
  718. X#define GridY(j)    (5 + Radius + (Game->Grid - (j) - 1 + 2) * 2 * Radius)
  719. X
  720. X#define DrawBlack(i,j,r) \
  721. X    pw_rop (BoardPW, GridX (i) - r, GridY (j) - r \
  722. X        , 2 * r + 1, 2 * r + 1, PIX_SRC, BlackStone, 0,0)
  723. X#define DrawWhite(i,j,r) \
  724. X    pw_rop (BoardPW, GridX (i) - r, GridY (j) - r \
  725. X        , 2 * r + 1, 2 * r + 1, PIX_SRC, WhiteStone, 0,0)
  726. X
  727. Xextern Canvas        BoardSW;
  728. Xextern Panel_item    CurrMoveSlider, LabelButton;
  729. Xextern Textsw        TextSW;
  730. Xextern int        UserTextMods, Verbose;
  731. X
  732. X
  733. XBackup (Game, Draw)
  734. X    GameType    *Game;
  735. X    int        Draw;
  736. X{
  737. Xint    i, j;
  738. XStone    s;    /* Other player. */
  739. Xchar    *String;
  740. XCaptureType    *Cap;
  741. X    if (Game->Placing) return;
  742. X    if (Game->MoveNum <= 0) return;
  743. X    if (Game->CurrMove == NULL) return;
  744. X    if (Draw && Game->CurrMove) PanelToLabel (Game->CurrMove->Next);
  745. X    Game->MoveNum--;
  746. X    i= Game->CurrMove->i;
  747. X    j= Game->CurrMove->j;
  748. X    if (Draw) {
  749. X    if (i >= 0) DrawEmpty (Game, i, j);
  750. X    if (Game->CurrMove->Next)
  751. X        DrawAltsEmpty (Game, Game->CurrMove);
  752. X    }
  753. X    if (i >= 0) RemoveStone (Game, i, j);
  754. X    if (Game->MoveNum & 1) s= Game->FirstPlayer;
  755. X    else s= !Game->FirstPlayer;
  756. X    if (Draw) SetFirstPlayerButton (!s, PANEL_CLEAR);
  757. X    for (Cap= Game->CurrMove->Captures; Cap != NULL; Cap= Cap->Next) {
  758. X    Game->Board [Cap->i] [Cap->j]= s;
  759. X    Game->Prisoners [s]--;
  760. X    NewStoneToGroups (Game, (int) Cap->i, (int) Cap->j);
  761. X    if (Draw) DrawMove (Game, NULL, Cap->i, Cap->j);
  762. X    }
  763. X    Game->CurrMove= Game->CurrMove->Prev;
  764. X    if (Draw) {
  765. X    Status (Game);
  766. X    StdMsg ();
  767. X    if (Game->CurrMove) {
  768. X        if (Verbose)
  769. X        HighlightMove (Game, Game->CurrMove, -1, -1);
  770. X        if (Game->CurrMove->Next)
  771. X        DrawAlts (Game, Game->CurrMove);
  772. X        NewText (Game->CurrMove->Note);
  773. X        LabelToPanel (Game->CurrMove->Next);
  774. X    } else {
  775. X        NewText (Game->Note);
  776. X    }
  777. X    }
  778. X    if (DebugLevel == 1) DebugGroups (Game->Groups);
  779. X} /* Backup */
  780. X
  781. X
  782. XDrawAlpha (Game, i, j, c)
  783. X    GameType *Game;
  784. X    int i, j;
  785. X    char *c;
  786. X{
  787. X    pw_text (BoardPW, GridX (i) - Radius / 2 + 1
  788. X    , GridY (j) + Radius / 2
  789. X    , PIX_SRC, Font, c);
  790. X} /* DrawAlpha */
  791. X
  792. X
  793. XDrawAlts (Game, Move)
  794. X    GameType *Game;
  795. X    MoveType *Move;
  796. X{
  797. XMoveType *m;
  798. X    if (!Verbose) return;
  799. X    for (m= Move->Next; m != NULL; ) {
  800. X    pw_rop (BoardPW, GridX (m->i) - Radius / 2
  801. X        , GridY (m->j) - Radius / 2
  802. X        , Radius, Radius, PIX_SRC | PIX_COLOR (0), NULL, 0, 0);
  803. X    if (m->Label [0] != '\0') DrawAlpha (Game, m->i, m->j, m->Label);
  804. X    m= m->AltNext;
  805. X    if (m == Move->Next) break;
  806. X    }
  807. X} /* DrawAlts */
  808. X
  809. X
  810. XDrawAltsEmpty (Game, Move)
  811. X    GameType *Game;
  812. X    MoveType *Move;
  813. X{
  814. XMoveType    *m;
  815. X    for (m= Move->Next; ; ) {
  816. X    DrawEmpty (Game, m->i, m->j);
  817. X    m= m->AltNext;
  818. X    if (m == Move->Next) break;
  819. X    }
  820. X} /* DrawAltsEmpty */
  821. X
  822. X
  823. XDrawEmpty (Game, i, j)
  824. X    GameType *Game;
  825. X    int i, j;
  826. X{
  827. X    pw_rop (BoardPW, GridX (i) - Radius
  828. X    , GridY (j) - Radius, 2 * Radius + 1, 2 * Radius + 1
  829. X    , PIX_SRC | PIX_COLOR (0), NULL, 0, 0);
  830. X    if (i > 0)
  831. X    pw_rop (BoardPW, GridX (i) - Radius, GridY (j) - 1
  832. X        , Radius + 1, LineWidth, PIX_SRC | PIX_COLOR (1), NULL, 0, 0);
  833. X    if (i < (Game->Grid - 1))
  834. X    pw_rop (BoardPW, GridX (i), GridY (j) - 1
  835. X        , Radius + 1, LineWidth, PIX_SRC | PIX_COLOR (1), NULL, 0, 0);
  836. X    if (j > 0)
  837. X    pw_rop (BoardPW, GridX (i) - 1, GridY (j)
  838. X        , LineWidth, Radius + 1, PIX_SRC | PIX_COLOR (1), NULL, 0, 0);
  839. X    if (j < (Game->Grid - 1))
  840. X    pw_rop (BoardPW, GridX (i) - 1, GridY (j) - Radius
  841. X        , LineWidth, Radius + 1, PIX_SRC | PIX_COLOR (1), NULL, 0, 0);
  842. X    if (((i == 3) || (i == Game->Grid / 2) || (i == Game->Grid - 4))
  843. X    && ((j == 3) || (j == Game->Grid / 2) || (j == Game->Grid - 4)))
  844. X        Disk (BoardPW, 2 * LineWidth, GridX (i), GridY (j), 1);
  845. X} /* DrawEmpty */
  846. X
  847. X
  848. XDrawGame (Game, ReCompBoard)
  849. X    GameType *Game;
  850. X{
  851. Xint i, j, k;
  852. XMoveType *Move;
  853. XCaptureType *c;
  854. XStone s;
  855. Xchar String [3];
  856. X    for (i= 0; i < Game->Grid; i++) {    /* Draw horizontals, then verticals. */
  857. X    pw_rop (BoardPW, GridX (i) - 1, GridX (0) - 1
  858. X        , LineWidth, (Game->Grid-1) * 2 * Radius
  859. X        , PIX_SRC | PIX_COLOR (1), NULL, 0, 0);
  860. X    sprintf (String, "%c", (i < 8) ? ('A' + i) : ('B' + i));
  861. X    pw_text (BoardPW, GridX (i) -1, GridX (-1) - 10, PIX_SRC, Font, String);
  862. X    pw_text (BoardPW, GridX (i) -1, GridX (Game->Grid + 2) - 10, PIX_SRC
  863. X        , Font, String);
  864. X    sprintf (String, "%2d", i + 1);
  865. X    pw_text (BoardPW, GridX (-1) - 20, GridY (i) +2, PIX_SRC, Font, String);
  866. X    pw_text (BoardPW, GridX (Game->Grid + 2) - 20, GridY (i) +2, PIX_SRC
  867. X        , Font, String);
  868. X    pw_rop (BoardPW, GridX (0) - 1, GridX (i) - 1
  869. X        , (Game->Grid-1) * 2 * Radius, LineWidth
  870. X        , PIX_SRC | PIX_COLOR (1), NULL, 0, 0);
  871. X    }
  872. X    /* Draw 9 handicap points (seimoku). */
  873. X    Disk (BoardPW, 2 * LineWidth, GridX (3), GridY (3), 1);
  874. X    Disk (BoardPW, 2 * LineWidth, GridX (3), GridY (Game->Grid / 2), 1);
  875. X    Disk (BoardPW, 2 * LineWidth, GridX (3), GridY (Game->Grid - 4), 1);
  876. X    Disk (BoardPW, 2 * LineWidth, GridX (Game->Grid / 2), GridY (3), 1);
  877. X    Disk (BoardPW, 2 * LineWidth, GridX (Game->Grid / 2)
  878. X    , GridY (Game->Grid / 2), 1);
  879. X    Disk (BoardPW, 2 * LineWidth, GridX (Game->Grid / 2)
  880. X    , GridY (Game->Grid - 4), 1);
  881. X    Disk (BoardPW, 2 * LineWidth, GridX (Game->Grid - 4), GridY (3), 1);
  882. X    Disk (BoardPW, 2 * LineWidth, GridX (Game->Grid - 4)
  883. X    , GridY (Game->Grid / 2), 1);
  884. X    Disk (BoardPW, 2 * LineWidth, GridX (Game->Grid - 4)
  885. X    , GridY (Game->Grid - 4), 1);
  886. X    /* Place stones on board according to Initial position. */
  887. X    for (i= 0; i < Game->Grid; i++) {
  888. X    for (j= 0; j < Game->Grid; j++) {
  889. X        if (Game->InitialBoard [i] [j] == Black) DrawBlack (i, j, Radius);
  890. X        else if (Game->InitialBoard [i] [j] == White)
  891. X        DrawWhite (i, j, Radius);
  892. X        if (ReCompBoard) Game->Board [i] [j]= Game->InitialBoard [i] [j];
  893. X    }
  894. X    }
  895. X    /* Place stones on board according to moves. */
  896. X    if (ReCompBoard) {
  897. X    s= Game->FirstPlayer;
  898. X    NullGroups (Game);
  899. X    Game->Prisoners [0]= Game->Prisoners [1]= 0;
  900. X    }
  901. X    for (k= 0, Move= Game->MoveList; (k < Game->MoveNum) && (Move!=NULL); k++){
  902. X    i= Move->i;
  903. X    j= Move->j;
  904. X    if (ReCompBoard) {
  905. X        if (i >= 0) {
  906. X        Game->Board [i] [j]= s;
  907. X        NewStoneToGroups (Game, i, j);
  908. X        if (GenCaptures (Game, !s, Move)) {
  909. X            for (c= Move->Captures; c != NULL; c= c->Next) {
  910. X            DrawEmpty (Game, c->i, c->j);
  911. X            }
  912. X        }
  913. X        }
  914. X        s= !s;
  915. X    }
  916. X    if (i >= 0) {
  917. X        if (Game->Board [i] [j] == Black) DrawBlack (i, j, Radius);
  918. X        else DrawWhite (i, j, Radius);
  919. X    }
  920. X    Game->CurrMove= Move;
  921. X    Move= Move->Next;
  922. X    }
  923. X    HighlightMove (Game, Game->CurrMove, -1, -1);
  924. X    panel_set (CurrMoveSlider, PANEL_VALUE, Game->MoveNum, 0);
  925. X    for ( ; Move != NULL; k++, Move= Move->Next);
  926. X        /* Find last move of this path. */
  927. X    panel_set (CurrMoveSlider, PANEL_MAX_VALUE, k, 0);
  928. X    if (Game->CurrMove) {
  929. X    LabelToPanel (Game->CurrMove->Next);
  930. X    NewText (Game->CurrMove->Note);
  931. X    if (Game->CurrMove->Next) DrawAlts (Game, Game->CurrMove);
  932. X    } else {
  933. X    NewText (Game->Note);
  934. X    }
  935. X} /* DrawGame */
  936. X
  937. X
  938. XDrawGameInit (Game, Width, Height)
  939. X    GameType *Game;
  940. X    int Width, Height;
  941. X{
  942. X    Radius= Width;
  943. X    if (Height < Width) Radius= Height;
  944. X    if (Radius > 650) {
  945. X    LineWidth= 3;
  946. X    Font= Fonts [3];
  947. X    } else if (Radius > 400) {
  948. X    LineWidth= 2;
  949. X    Font= Fonts [2];
  950. X    } else if (Radius > 300) {
  951. X    LineWidth= 1;
  952. X    Font= Fonts [1];
  953. X    } else {
  954. X    LineWidth= 1;
  955. X    Font= Fonts [0];
  956. X    }
  957. X    Radius= Radius - 10;
  958. X    Radius= Radius / (Game->Grid + 4);
  959. X    Radius= Radius / 2;
  960. X    if (BlackStone != NULL) pr_destroy (BlackStone);
  961. X    if (WhiteStone != NULL) pr_destroy (WhiteStone);
  962. X    BlackStone= mem_create (2 * Radius + 1, 2 * Radius + 1, 1);
  963. X    WhiteStone= mem_create (2 * Radius + 1, 2 * Radius + 1, 1);
  964. X    /* Create stone pixrects. */
  965. X    DiskPR (BlackStone, Radius, Radius, Radius, 1);
  966. X    DiskPR (WhiteStone, Radius, Radius, Radius, 1);
  967. X    DiskPR (WhiteStone, Radius - LineWidth, Radius, Radius, 0);
  968. X} /* DrawGameInit */
  969. X
  970. X
  971. XDrawMove (Game, m, i, j)
  972. X    GameType *Game;
  973. X    MoveType *m;
  974. X    int i, j;
  975. X{
  976. X/* Assume move is already on board. */
  977. X    if (Game->Board [i] [j] == Black) DrawBlack (i, j, Radius);
  978. X    else DrawWhite (i, j, Radius);
  979. X    if (Verbose && m) HighlightMove (Game, m, -1, -1);
  980. X} /* DrawMove */
  981. X
  982. X
  983. XEnterMove (i, j, Game, Draw, Action)
  984. X    int i, j;
  985. X    GameType *Game;
  986. X    int Draw, Action;
  987. X{
  988. Xint NumCaptures, Count;
  989. XMoveType *m, *m1;
  990. XStone s;
  991. XGroupType *Neighbors [4], *g;
  992. X    if (Game->CurrMove != NULL) PanelToLabel (Game->CurrMove->Next);
  993. X    if (Action == PassAction) {
  994. X    i= -1;
  995. X    j= -1;
  996. X    } else {
  997. X    if ((i < 0) || (i >= Game->Grid) || (j < 0) || (j >= Game->Grid))
  998. X        return 1;
  999. X    }
  1000. X    if (Game->Placing) {
  1001. X    if (Action != PassAction) {
  1002. X        Game->Board [i][j]= Game->InitialBoard [i][j]= Game->FirstPlayer;
  1003. X        DrawMove (Game, NULL, i, j);
  1004. X        return 0;
  1005. X    } else return 0;
  1006. X    }
  1007. X    if (Action != PassAction) {
  1008. X    if (Game->Board [i] [j] != Empty) return 1;
  1009. X    }
  1010. X    if (Game->MoveNum & 1) s= !Game->FirstPlayer;
  1011. X    else s= Game->FirstPlayer;
  1012. X    if (Action != PassAction) {        /* Check legality of move */
  1013. X    g= AllocGroup (s, 0, 0);
  1014. X    CountGrpLibs (Game, i, j, s, g, 0);
  1015. X    if (g->NumLibs <= 0) {
  1016. X        NumCaptures= CheckCaptures (Game, !s, i, j);
  1017. X        if (FindFriends (i, j, Game, s, Neighbors) && (NumCaptures == 0)) { 
  1018. X        /* Undo suicide. */
  1019. X        FreeGroup (g);
  1020. X        StatusMsg ("Illegal move (suicide).");
  1021. X        return 1;
  1022. X        } else {    /* Detect ko or single suicide. */
  1023. X        if (NumCaptures == 0) {
  1024. X            /* Undo suicide. */
  1025. X            FreeGroup (g);
  1026. X            StatusMsg ("Illegal move (suicide).");
  1027. X            return 1;
  1028. X        } else if (NumCaptures == 1) {    /* Check for ko violation. */
  1029. X            if ((Game->CurrMove != NULL)
  1030. X            && (Game->CurrMove->Captures != NULL)
  1031. X            && (Game->CurrMove->Captures->Next == NULL)
  1032. X            && (Game->CurrMove->Captures->i == i)
  1033. X            && (Game->CurrMove->Captures->j == j)) {
  1034. X                /* ko violation. */
  1035. X            FreeGroup (g);
  1036. X            StatusMsg ("Illegal move (ko violation).");
  1037. X            return 2;
  1038. X            }
  1039. X        }
  1040. X        }
  1041. X    }
  1042. X    FreeGroup (g);
  1043. X    }
  1044. X    if ((Game->MoveList == NULL) || (Action == MoveAction)
  1045. X        || (Action == PassAction)) {
  1046. X    /* Get rid of moves beyond current move. */
  1047. X/*    if (Game->NumMoves != Game->MoveNum) { */
  1048. X        if (Game->CurrMove != NULL) {
  1049. X        if (Draw && Verbose && Game->CurrMove->Next)
  1050. X            DrawEmpty (Game, Game->CurrMove->Next->i
  1051. X            , Game->CurrMove->Next->j);
  1052. X        FreeMoves (Game->CurrMove->Next);
  1053. X        Game->CurrMove->Next= NULL;
  1054. X        } else {
  1055. X        FreeMoves (Game->MoveList);
  1056. X        }
  1057. X/*    } */
  1058. X    m= AllocMove (i, j, Game->CurrMove);
  1059. X    if (Game->MoveList == NULL) Game->MoveList= m;
  1060. X    Game->NumMoves= Game->MoveNum + 1;
  1061. X    panel_set (CurrMoveSlider, PANEL_MAX_VALUE, Game->NumMoves
  1062. X        , PANEL_PAINT, PANEL_CLEAR, 0);
  1063. X    } else if (Action == AltMoveAction) {
  1064. X#define NEW
  1065. X#ifdef NEW
  1066. X    m1= Game->CurrMove->Next;
  1067. X    m= AllocMove (i, j, Game->CurrMove);
  1068. X    Game->NumMoves= Game->MoveNum + 1;
  1069. X    panel_set (CurrMoveSlider, PANEL_MAX_VALUE, Game->NumMoves
  1070. X        , PANEL_PAINT, PANEL_CLEAR, 0);
  1071. X    if (m1 != NULL) {
  1072. X        if ((m1->Label [0] == ' ') || (m1->Label [0] == 0))
  1073. X        m1->Label [0]= 'a';
  1074. X        m->AltNext= m1;
  1075. X        m->AltPrev= m1->AltPrev;
  1076. X        m1->AltPrev= m;
  1077. X        m->AltPrev->AltNext= m;
  1078. X        for (m1= m->AltNext, Count= 1; m1 != m; m1= m1->AltNext)
  1079. X        m1->Label [0]= 'a' + Count++;
  1080. X        m->Label [0]= 'a';
  1081. X        LabelToPanel (m); /* Step will PanelToLabel(Game->CurrMove->Next) */
  1082. X    }
  1083. X#else
  1084. X    if (Game->CurrMove != NULL) {
  1085. X        if ((Game->CurrMove->Label [0] == ' ')
  1086. X        || (Game->CurrMove->Label [0] == 0))
  1087. X        Game->CurrMove->Label [0]= 'a';
  1088. X        LabelToPanel (Game->CurrMove->Next);
  1089. X        m= AllocMove (i, j, Game->CurrMove->Prev);
  1090. X        m->AltPrev= Game->CurrMove;
  1091. X        m->AltNext= Game->CurrMove->AltNext;
  1092. X        Game->CurrMove->AltNext= m;
  1093. X        m->AltNext->AltPrev= m;
  1094. X        if (Game->CurrMove->Prev == NULL) Game->MoveList= m;
  1095. X        else Game->CurrMove->Prev->Next= m;
  1096. X        for (m1= m->AltNext, Count= 0; m1 != m; m1= m1->AltNext) Count++;
  1097. X        m->Label [0]= 'a' + Count;
  1098. X        Backup (Game, Draw);
  1099. X    } else Cafard ("AltMoveAction:  Game->CurrMove == NULL");
  1100. X#endif
  1101. X    }
  1102. X    Step (Game, Draw);
  1103. X    return 0;
  1104. X} /* EnterMove */
  1105. X
  1106. X
  1107. XHighlightMove (Game, m, ii, jj)
  1108. X    GameType    *Game;
  1109. X    MoveType    *m;
  1110. X    int     ii, jj;
  1111. X/* If (m) use it for i and j; otherwise use ii and jj. */
  1112. X{
  1113. Xint i, j;
  1114. Xint Color;
  1115. X    if (m) {
  1116. X    i= m->i;
  1117. X    j= m->j;
  1118. X    } else {
  1119. X    i= ii;
  1120. X    j= jj;
  1121. X    }
  1122. X    if (Game->Board [i][j] == Black) Color= 0; else Color= 1;
  1123. X    if (1 || m->Label [0] < 'a')
  1124. X    Disk (BoardPW, 2 * LineWidth, GridX (i), GridY (j), Color);
  1125. X    else
  1126. X    pw_text (BoardPW, GridX (i) - Radius / 2 + 1
  1127. X        , GridY (j) + Radius / 2
  1128. X        , PIX_SRC ^ PIX_DST, Font, m->Label);
  1129. X} /* HighlightMove */
  1130. X
  1131. X
  1132. XNewText (Msg)
  1133. X    char *Msg;
  1134. X{
  1135. Xchar Junk [3];
  1136. X    if (Msg == NULL) {
  1137. X    Junk [0]= '\n';
  1138. X    Junk [1]= '\n';
  1139. X    Junk [2]= '\0';
  1140. X    Msg= Junk;
  1141. X    }
  1142. X    textsw_replace (TextSW, 0, TEXTSW_INFINITY, Msg, strlen (Msg));
  1143. X    window_set (TextSW, TEXTSW_INSERTION_POINT, TEXTSW_INFINITY, 0);
  1144. X    textsw_insert (TextSW, "\n", 1);
  1145. X    window_set (TextSW, TEXTSW_INSERTION_POINT, 0, 0);
  1146. X    UserTextMods= 0;
  1147. X    if (Verbose) textsw_normalize_view (TextSW, 0);
  1148. X    else textsw_normalize_view (TextSW, TEXTSW_INFINITY);
  1149. X/*    textsw_display (TextSW);*/
  1150. X} /* NewText */
  1151. X
  1152. X
  1153. XReplay (Game, ReCompBoard)
  1154. X    GameType *Game;
  1155. X    int ReCompBoard;
  1156. X{
  1157. Xstruct rect *r;
  1158. X    r= (struct rect *) window_get (BoardSW, WIN_RECT);
  1159. X    pw_writebackground (BoardPW, 0, 0, r->r_width, r->r_height, PIX_CLR);
  1160. X/*
  1161. X    DrawGameInit (Game, r->r_width, r->r_height);
  1162. X*/
  1163. X    DrawGame (Game, ReCompBoard);
  1164. X} /* Replay */
  1165. X
  1166. X
  1167. XSetHandicap (Game, Value)
  1168. X    GameType *Game;
  1169. X    int Value;
  1170. X/* Set handicap value and set first-player accordingly. */
  1171. X{
  1172. X    if (Value < 2) Value= 0;
  1173. X    else if (Value > MaxHandicap) Value= MaxHandicap;
  1174. X    if (Value == 0) {
  1175. X    Game->Handicap= 0;
  1176. X    Game->FirstPlayer= Black;
  1177. X    } else {
  1178. X    Game->Handicap= Value;
  1179. X    Game->FirstPlayer= White;
  1180. X    }
  1181. X} /* SetHandicap */
  1182. X
  1183. X
  1184. XSideways (Game, Draw)
  1185. X    GameType *Game;
  1186. X    int Draw;
  1187. X{
  1188. XMoveType *m;
  1189. X    m= Game->CurrMove->AltNext;
  1190. X    if (Game->CurrMove->Prev != NULL) {
  1191. X    Backup (Game, Draw);
  1192. X    Game->CurrMove->Next= m;
  1193. X    Step (Game, Draw);
  1194. X    }
  1195. X} /* Sideways */
  1196. X
  1197. X
  1198. XStep (Game, Draw)
  1199. X    GameType *Game;
  1200. X    int Draw;
  1201. X{
  1202. Xint    i, j;
  1203. XStone    s;
  1204. XCaptureType    *c;
  1205. X    if (Game->Placing) return;
  1206. X    if (Game->CurrMove == NULL) {
  1207. X    Game->MoveNum= 0;
  1208. X    if (Game->MoveList == NULL) return;
  1209. X    Game->CurrMove= Game->MoveList;
  1210. X    } else {
  1211. X    if (Draw) {
  1212. X        PanelToLabel (Game->CurrMove->Next);
  1213. X        if (Game->CurrMove->Next)
  1214. X        DrawAltsEmpty (Game, Game->CurrMove);
  1215. X    }
  1216. X    if (Game->CurrMove->Next == NULL) return;
  1217. X    Game->CurrMove= Game->CurrMove->Next;
  1218. X    }
  1219. X    Game->MoveNum++;
  1220. X    if (Game->MoveNum & 1) s= Game->FirstPlayer;
  1221. X    else s= !Game->FirstPlayer;
  1222. X    if (Draw) SetFirstPlayerButton (!s, PANEL_CLEAR);
  1223. X    i= Game->CurrMove->i;
  1224. X    if (i >= 0) {
  1225. X    Game->Board [i] [j= Game->CurrMove->j]= s;
  1226. X    if (Draw) DrawMove (Game, Game->CurrMove, i, j);
  1227. X    NewStoneToGroups (Game, i, j);
  1228. X    if (GenCaptures (Game, !s, Game->CurrMove)) {
  1229. X        if (Draw) {
  1230. X        for (c= Game->CurrMove->Captures; c != NULL; c= c->Next) {
  1231. X            DrawEmpty (Game, c->i, c->j);
  1232. X        }
  1233. X        }
  1234. X    }
  1235. X    }
  1236. X    if (Draw) {
  1237. X    Status (Game);
  1238. X    StdMsg ();
  1239. X    if ((Game->CurrMove) && (Game->CurrMove->Prev)) {
  1240. X        i= Game->CurrMove->Prev->i;
  1241. X        j= Game->CurrMove->Prev->j;
  1242. X        UnHighlightMove (Game, i, j);
  1243. X    }
  1244. X    if (Game->CurrMove) {
  1245. X        if (Game->CurrMove->Next) DrawAlts (Game, Game->CurrMove);
  1246. X        NewText (Game->CurrMove->Note);
  1247. X        LabelToPanel (Game->CurrMove->Next);
  1248. X    } else {
  1249. X        NewText (Game->CurrMove->Note);
  1250. X    }
  1251. X    }
  1252. X} /* Step */
  1253. X
  1254. X
  1255. XUnHighlightMove (Game, i, j)
  1256. X    GameType    *Game;
  1257. X    int     i, j;
  1258. X{
  1259. Xint Color;
  1260. X    if (Game->Board [i][j] == Black) Color= 1;
  1261. X    else if (Game->Board [i][j] == White) Color= 0;
  1262. X    else return;
  1263. X    Disk (BoardPW, 2 * LineWidth, GridX (i), GridY (j), Color);
  1264. X} /* UnHighlightMove */
  1265. END_OF_FILE
  1266. if test 15937 -ne `wc -c <'goboard.c'`; then
  1267.     echo shar: \"'goboard.c'\" unpacked with wrong size!
  1268. fi
  1269. # end of 'goboard.c'
  1270. fi
  1271. if test -f 'gocapture.c' -a "${1}" != "-c" ; then 
  1272.   echo shar: Will not clobber existing file \"'gocapture.c'\"
  1273. else
  1274. echo shar: Extracting \"'gocapture.c'\" \(12236 characters\)
  1275. sed "s/^X//" >'gocapture.c' <<'END_OF_FILE'
  1276. X#ifndef lint
  1277. Xstatic char sccsid[]= "@(#)gocapture.c 1.3 87/01/11 Copyr 1986 Sun Micro";
  1278. X#endif
  1279. X
  1280. X/* Copyright (c) Sun MicroSystems, 1986.  This code may be used and modified
  1281. X    for not-for-profit use.  This notice must be retained.  */
  1282. X
  1283. X#include "goban.h"
  1284. X
  1285. X
  1286. XGroupType *UniteGroups ();
  1287. X
  1288. X
  1289. XCheckCaptures (Game, Color, i, j)
  1290. X    GameType *Game;
  1291. X    Stone Color;
  1292. X    int i, j;
  1293. X/* Find all unique groups of Color with no liberties.
  1294. X    Color is the opposite color to the moving player.
  1295. X    Returns number of stones that would be captured.
  1296. X*/
  1297. X{
  1298. Xint NumGroups, NumCaptures, k, kk, kkk;
  1299. XGroupType *Captures [4];
  1300. X    NumGroups= 0;
  1301. X    if ((i > 0) && (Game->Board [i-1][j] == Color) &&
  1302. X    (Game->Groups [i-1][j]->NumLibs <= 1))
  1303. X    Captures [NumGroups++]= Game->Groups [i-1][j];
  1304. X    if ((j > 0) && (Game->Board [i][j-1] == Color) &&
  1305. X    (Game->Groups [i][j-1]->NumLibs <= 1))
  1306. X    Captures [NumGroups++]= Game->Groups [i][j-1];
  1307. X    if ((i < (Game->Grid-1)) && (Game->Board [i+1][j] == Color) &&
  1308. X    (Game->Groups [i+1][j]->NumLibs <= 1))
  1309. X    Captures [NumGroups++]= Game->Groups [i+1][j];
  1310. X    if ((j < (Game->Grid-1)) && (Game->Board [i][j+1] == Color) &&
  1311. X    (Game->Groups [i][j+1]->NumLibs <= 1))
  1312. X    Captures [NumGroups++]= Game->Groups [i][j+1];
  1313. X    for (k= 1; k < NumGroups; k++) {
  1314. X    for (kk= 0; kk < k; kk++) {
  1315. X        if (Captures [k] == Captures [kk]) {
  1316. X        for (kkk= k+1; kkk < NumGroups; kkk++) {
  1317. X            Captures [kkk-1]= Captures [kkk];
  1318. X        }
  1319. X        NumGroups--;
  1320. X        }
  1321. X    }
  1322. X    }
  1323. X    for (k= 0, NumCaptures= 0; k < NumGroups; k++)
  1324. X    NumCaptures += Captures [k]->NumStones;
  1325. X    return NumCaptures;
  1326. X} /* CheckCaptures */
  1327. X
  1328. X
  1329. XCountGrpLibs (Game, i, j, Match, g, RecursionLevel)
  1330. X    GameType *Game;
  1331. X    int i, j;
  1332. X    Stone Match;
  1333. X    GroupType *g;
  1334. X    int RecursionLevel;    /* Zero on first call. */
  1335. X{
  1336. X
  1337. X#define CountGrpLibs0(a,b,c) \
  1338. X    if ((a) && (Checked [b][c] < CheckNum)) { \
  1339. X    Checked [b][c]= CheckNum; \
  1340. X    Color= Game->Board [b][c]; \
  1341. X    if (Color == Match) CountGrpLibs (Game, b, c, Match, g, 1); \
  1342. X    else if (Color == Empty) g->NumLibs++; \
  1343. X    }
  1344. X
  1345. XStone Color;
  1346. X    if (RecursionLevel == 0) {
  1347. X    g->NumLibs= 0;
  1348. X    Checked [i][j]= ++CheckNum;
  1349. X    }
  1350. X    CountGrpLibs0 ((i > 0), i-1, j);
  1351. X    CountGrpLibs0 ((j > 0), i, j-1);
  1352. X    CountGrpLibs0 ((i < Game->Grid-1), i+1, j);
  1353. X    CountGrpLibs0 ((j < Game->Grid-1), i, j+1);
  1354. X} /* CountGrpLibs */
  1355. X
  1356. X
  1357. X    int
  1358. XCountLibs (Game, i, j)
  1359. X    GameType *Game;
  1360. X    int i, j;
  1361. X/* Count liberties of a single isolated stone.
  1362. X    Assumes stone is already on board.
  1363. X*/
  1364. X{
  1365. Xint NumLibs, LastLine;
  1366. X    LastLine= Game->Grid - 1;
  1367. X    NumLibs= 0;
  1368. X    if ((i > 0) && (Game->Board [i-1][j] == Empty)) {
  1369. X    NumLibs++;
  1370. X    }
  1371. X    if ((j > 0) && (Game->Board [i][j-1] == Empty)) {
  1372. X    NumLibs++;
  1373. X    }
  1374. X    if ((i < LastLine) && (Game->Board [i+1][j] == Empty)) {
  1375. X    NumLibs++;
  1376. X    }
  1377. X    if ((j < LastLine) && (Game->Board [i][j+1] == Empty)) {
  1378. X    NumLibs++;
  1379. X    }
  1380. X    return NumLibs;
  1381. X} /* CountLibs */
  1382. X
  1383. X
  1384. XDebugGroups (Groups)
  1385. X    GroupType *Groups [MaxGrid] [MaxGrid];
  1386. X{
  1387. XGroupType *g;
  1388. Xint i, j;
  1389. X    for (j= 9; j >= 3; j--) {
  1390. X    for (i= 13; i < 19; i++) {
  1391. X        g= Groups [i] [j];
  1392. X        printf ("  %7lx", g);
  1393. X        if (g != NULL) printf (" %c%d", g->Color ? 'o' : '*', g->NumLibs);
  1394. X        else printf ("   ");
  1395. X    }
  1396. X    printf ("\n");
  1397. X    }
  1398. X    printf ("\n");
  1399. X} /* DebugGroups */
  1400. X
  1401. X
  1402. X    int
  1403. XFindEnemies (i, j, Game, Enemies)
  1404. X    int i, j;
  1405. X    GameType *Game;
  1406. X    GroupType *Enemies [4];
  1407. X/* Call by reference variable side effect:  Enemies. 
  1408. X    Returns number of neighboring stones found of opposing color.
  1409. X    Watch out for stone touching a group twice.
  1410. X*/
  1411. X{
  1412. Xint Num, k, c;    /* c == color. */
  1413. X    c= !Game->Board [i][j];
  1414. X    Num= 0;
  1415. X    if ((i > 0) && (Game->Board [i-1][j] == c))
  1416. X    Enemies [Num++]= Game->Groups [i-1][j];
  1417. X    if ((j > 0) && (Game->Board [i][j-1] == c))
  1418. X    Enemies [Num++]= Game->Groups [i][j-1];
  1419. X    if ((i < (Game->Grid - 1)) && (Game->Board [i+1][j] == c))
  1420. X    Enemies [Num++]= Game->Groups [i+1][j];
  1421. X    if ((j < (Game->Grid - 1)) && (Game->Board [i][j+1] == c))
  1422. X    Enemies [Num++]= Game->Groups [i][j+1];
  1423. X    /* Check for Duplicates. */
  1424. X    for (i= 0; i < (Num-1); i++) {
  1425. X    for (j= i+1; j < Num; j++) {
  1426. X        if (Enemies [i] == Enemies [j]) {
  1427. X        for (k= j; k < (Num-1); k++) Enemies [k]= Enemies [k+1];
  1428. X        Num--;
  1429. X        j--;    /* Since a new neighbor is at j position. */
  1430. X        }
  1431. X    }
  1432. X    }
  1433. X    return Num;
  1434. X} /* FindEnemies */
  1435. X
  1436. X
  1437. X    int
  1438. XFindFriends (i, j, Game, c, Neighbors)
  1439. X    int i, j;
  1440. X    GameType *Game;
  1441. X    int c;    /* c == color. */
  1442. X    GroupType *Neighbors [4];
  1443. X/* Call by reference variable side effect:  Neighbors. 
  1444. X    Returns number of neighboring stones found of same color.
  1445. X    Watch out for stone touching a group twice.
  1446. X*/
  1447. X{
  1448. Xint Num, k;
  1449. X    Num= 0;
  1450. X    if ((i > 0) && (Game->Board [i-1][j] == c))
  1451. X    Neighbors [Num++]= Game->Groups [i-1][j];
  1452. X    if ((j > 0) && (Game->Board [i][j-1] == c))
  1453. X    Neighbors [Num++]= Game->Groups [i][j-1];
  1454. X    if ((i < (Game->Grid - 1)) && (Game->Board [i+1][j] == c))
  1455. X    Neighbors [Num++]= Game->Groups [i+1][j];
  1456. X    if ((j < (Game->Grid - 1)) && (Game->Board [i][j+1] == c))
  1457. X    Neighbors [Num++]= Game->Groups [i][j+1];
  1458. X    /* Eliminate Duplicates. */
  1459. X    for (i= 0; i < (Num-1); i++) {
  1460. X    for (j= i+1; j < Num; j++) {
  1461. X        if (Neighbors [i] == Neighbors [j]) {
  1462. X        for (k= j; k < (Num-1); k++) Neighbors [k]= Neighbors [k+1];
  1463. X        Num--;
  1464. X        j--;    /* Since a new neighbor is at j position. */
  1465. X        }
  1466. X    }
  1467. X    }
  1468. X    return Num;
  1469. X} /* FindFriends */
  1470. X
  1471. X
  1472. X    int 
  1473. XGenCaptures (Game, Color, Move)
  1474. X    GameType *Game;
  1475. X    int Color;
  1476. X    MoveType *Move;
  1477. X/* Find all groups of Color with no liberties and removes them, putting
  1478. X    the captures into the Move.  Color is the opposite color to the
  1479. X    moving player.
  1480. X*/
  1481. X{
  1482. Xint i, j, k, NumCaptures;
  1483. XGroupType **g, *Grp, *Neighbors [4];
  1484. XCaptureType *c;
  1485. XStone *s;
  1486. X    if (Move->Captures != NULL) {
  1487. X    FreeCaptures (Move->Captures);
  1488. X    Move->Captures= NULL;
  1489. X    }
  1490. X    for (i= 0, NumCaptures= 0; i < Game->Grid; i++) {
  1491. X    g= Game->Groups [i];
  1492. X    s= Game->Board [i];
  1493. X    for (j= 0; j < Game->Grid; j++, s++, g++) {
  1494. X        Grp= *g;
  1495. X        if ((Grp != NULL) && (Grp->Color == Color)) {
  1496. X        if (Grp->NumLibs == 0) {
  1497. X            NumCaptures++;
  1498. X            k= FindEnemies (i, j, Game, Neighbors) - 1;
  1499. X            for (; k >= 0; k--) {
  1500. X            Neighbors [k]->NumLibs++;
  1501. X            }
  1502. X            *s= Empty;
  1503. X            Game->Prisoners [Color]++;
  1504. X            c= AllocCapture (i, j);
  1505. X            c->Next= Move->Captures;
  1506. X            Move->Captures= c;
  1507. X            Grp->NumStones--;
  1508. X            if (Grp->NumStones <= 0)
  1509. X            FreeGroup (Grp);
  1510. X            *g= NULL;
  1511. X        }
  1512. X        }
  1513. X    }
  1514. X    }
  1515. X    return NumCaptures;
  1516. X} /* GenCaptures */
  1517. X
  1518. X
  1519. XNewStoneToGroups (Game, i, j)
  1520. X    GameType *Game;
  1521. X    int i, j;
  1522. X/* Adjusts group map to include presence of new stone at i, j.
  1523. X*/
  1524. X{
  1525. XGroupType    *g, *Neighbors [4];
  1526. X    /* First stores Neighbors, then Enemies. */
  1527. Xint         NumNeighbors, NumEnemies;
  1528. Xint        k;
  1529. X    if (Game->Board [i][j] == Empty) {
  1530. X    fprintf (stderr, "NewStonetoGroups (%d, %d, Game) is Empty.\n", i, j);
  1531. X    }
  1532. X    NumNeighbors= FindFriends (i, j, Game, Game->Board [i][j], Neighbors);
  1533. X    switch (NumNeighbors) {
  1534. X    case 0:    /* New Group */
  1535. X    Game->Groups [i][j]= g= AllocGroup (Game->Board [i][j], 0, 1);
  1536. X    g->NumLibs = CountLibs (Game, i, j);
  1537. X    break;
  1538. X    case 1:
  1539. X    g= Game->Groups [i][j]= Neighbors [0];
  1540. X    g->NumStones++;
  1541. X    CountGrpLibs (Game, i, j, Game->Board [i][j], g, 0);
  1542. X    break;
  1543. X    default:
  1544. X    g= UniteGroups (i, j, Neighbors, NumNeighbors, Game);
  1545. X    } /* switch */
  1546. X    NumEnemies= FindEnemies (i, j, Game, Neighbors);
  1547. X    for (k= 0; k < NumEnemies; k++) Neighbors [k]->NumLibs--;
  1548. X    if (DebugLevel == 1) {
  1549. X    printf ("NewStonetoGroups %d %d\n", i, j);
  1550. X    DebugGroups (Game->Groups);
  1551. X    }
  1552. X} /* NewStoneToGroups */
  1553. X
  1554. X
  1555. XNullGroups (Game)
  1556. X    GameType *Game;
  1557. X/* Set Group map entries to NULL. */
  1558. X{
  1559. Xint i, j;
  1560. X    for (i= 0; i < MaxGrid; i++)
  1561. X    for (j= 0; j < MaxGrid; j++)
  1562. X        if (Game->Groups [i][j] != NULL) {
  1563. X        FreeGroup (Game->Groups [i][j]);
  1564. X        Game->Groups [i][j]= NULL;
  1565. X        }
  1566. X    for (i= 0; i < MaxGrid; i++)
  1567. X    for (j= 0; j < MaxGrid; j++)
  1568. X        if (Game->InitialBoard [i][j] != Empty) {
  1569. X        Game->Groups [i][j]= 
  1570. X            AllocGroup (Game->InitialBoard [i][j], 4, 1);
  1571. X        }
  1572. X} /* NullGroups */
  1573. X
  1574. X
  1575. X    int
  1576. XRemGroup (Game, i, j, c, Dir, LastLine)
  1577. X    GameType *Game;
  1578. X    int i, j;
  1579. X    Stone c;
  1580. X    int Dir, LastLine;
  1581. X    /* Dir is Direction this call is going. */
  1582. X{
  1583. Xint s = 0;
  1584. XGroupType *g;
  1585. X    if (Dir == NoDir) g= Game->Groups [i][j];
  1586. X    Game->Groups [i][j]= NULL;
  1587. X    if ((Dir != East) && (i > 0) && (Game->Board [i-1][j] == c)
  1588. X    && (Game->Groups [i-1][j] != NULL)) {
  1589. X    s |= West;
  1590. X    RemGroup (Game, i-1, j, c, West, LastLine);
  1591. X    }
  1592. X    if ((Dir != North) && (j > 0) && (Game->Board [i][j-1] == c)
  1593. X    && (Game->Groups [i][j-1] != NULL)) {
  1594. X    s |= South;
  1595. X    RemGroup (Game, i, j-1, c, South, LastLine);
  1596. X    }
  1597. X    if ((Dir != West) && (i < LastLine) && (Game->Board [i+1][j] == c)
  1598. X    && (Game->Groups [i+1][j] != NULL)) {
  1599. X    s |= East;
  1600. X    RemGroup (Game, i+1, j, c, East, LastLine);
  1601. X    }
  1602. X    if ((Dir != South) && (j < LastLine) && (Game->Board [i][j+1] == c)
  1603. X    && (Game->Groups [i][j+1] != NULL)) {
  1604. X    s |= North;
  1605. X    RemGroup (Game, i, j+1, c, North, LastLine);
  1606. X    }
  1607. X    if (Dir == NoDir) FreeGroup (g);
  1608. X    return s;
  1609. X} /* RemGroup */
  1610. X
  1611. X
  1612. XRemoveStone (Game, i, j)
  1613. X    GameType *Game;
  1614. X    int i, j;
  1615. X/* When splitting the group that the stone i,j is in, be sure to
  1616. X    watch for a group that comes around and touches twice.
  1617. X*/
  1618. X{
  1619. X#define NullGrp    (GroupType *) NULL
  1620. Xint LastLine, Dirs, k;
  1621. XStone c;
  1622. XGroupType *Neighbors [4];
  1623. X    for (k= FindEnemies (i, j, Game, Neighbors) - 1; k >= 0; k--) {
  1624. X    Neighbors [k]->NumLibs++;
  1625. X    }
  1626. X    c= Game->Board [i][j];
  1627. X    Game->Board [i][j]= Empty;
  1628. X    LastLine= Game->Grid - 1;
  1629. X    if (Dirs= RemGroup (Game, i, j, c, NoDir, LastLine)) {
  1630. X    if (Dirs & West) {
  1631. X        RestoreGroup (Game, i-1, j, c, West, LastLine, NullGrp);
  1632. X        CountGrpLibs (Game, i-1, j, c, Game->Groups [i-1][j], 0);
  1633. X    }
  1634. X    if (Dirs & South) {
  1635. X        RestoreGroup (Game, i, j-1, c, South, LastLine, NullGrp);
  1636. X        CountGrpLibs (Game, i, j-1, c, Game->Groups [i][j-1], 0);
  1637. X    }
  1638. X    if (Dirs & East) {
  1639. X        RestoreGroup (Game, i+1, j, c, East, LastLine, NullGrp);
  1640. X        CountGrpLibs (Game, i+1, j, c, Game->Groups [i+1][j], 0);
  1641. X    }
  1642. X    if (Dirs & North) {
  1643. X        RestoreGroup (Game, i, j+1, c, North, LastLine, NullGrp);
  1644. X        CountGrpLibs (Game, i, j+1, c, Game->Groups [i][j+1], 0);
  1645. X    }
  1646. X    }
  1647. X} /* RemoveStone */
  1648. X
  1649. X
  1650. XRestoreGroup (Game, i, j, c, Dir, LastLine, g)
  1651. X    GameType *Game;
  1652. X    int i, j;
  1653. X    Stone c;
  1654. X    int Dir, LastLine;
  1655. X    GroupType *g;
  1656. X/* Seeks out stones and fills in group map.  Used for each branch when
  1657. X    removing a single stone splits a group.  Since all contiguous stones
  1658. X    have just prior been removed, don't have to worry about uniting groups.
  1659. X*/
  1660. X{
  1661. X    if (g == NULL) {
  1662. X    g= AllocGroup (c, 0, 1);
  1663. X    Game->Groups [i][j]= g;
  1664. X    } else {
  1665. X    Game->Groups [i][j]= g;
  1666. X    g->NumStones++;
  1667. X    }
  1668. X    if ((Dir != East) && (i > 0) && (Game->Board [i-1][j] == c)
  1669. X    && (Game->Groups [i-1] [j] != g)) {
  1670. X    RestoreGroup (Game, i-1, j, c, West, LastLine, g);
  1671. X    }
  1672. X    if ((Dir != North) && (j > 0) && (Game->Board [i][j-1] == c)
  1673. X    && (Game->Groups [i] [j-1] != g)) {
  1674. X    RestoreGroup (Game, i, j-1, c, South, LastLine, g);
  1675. X    }
  1676. X    if ((Dir != West) && (i < LastLine) && (Game->Board [i+1][j] == c)
  1677. X    && (Game->Groups [i+1] [j] != g)) {
  1678. X    RestoreGroup (Game, i+1, j, c, East, LastLine, g);
  1679. X    }
  1680. X    if ((Dir != South) && (j < LastLine) && (Game->Board [i][j+1] == c)
  1681. X    && (Game->Groups [i] [j+1] != g)) {
  1682. X    RestoreGroup (Game, i, j+1, c, North, LastLine, g);
  1683. X    }
  1684. X} /* RestoreGroup */
  1685. X
  1686. X
  1687. X    GroupType *
  1688. XUniteGroups (ii, jj, Neighbors, NumNeighbors, Game)
  1689. X    int ii, jj;
  1690. X    GroupType *Neighbors [4];
  1691. X    int NumNeighbors;
  1692. X    GameType *Game;
  1693. X/* Unite Group of Stone ii, jj with list of Neighbors.  Group of ii, jj
  1694. X    is subsumed by last Neighbor which subsumes the other neighbor groups.
  1695. X    Free Neighbor groups.
  1696. X*/
  1697. X{
  1698. XGroupType *g;
  1699. Xint i, j, k;
  1700. XStone c;
  1701. X    c= Game->Board [ii][jj];
  1702. X    g= Neighbors [--NumNeighbors];
  1703. X    Game->Groups [ii][jj]= g;
  1704. X    g->NumStones++;    /* for stone at ii, jj. */
  1705. X    if (NumNeighbors <= 0) return 0;
  1706. X    for (i= 0; i < Game->Grid; i++) {
  1707. X    for (j= 0; j < Game->Grid; j++) {
  1708. X        for (k= 0; k < NumNeighbors; k++)
  1709. X        if (Game->Groups [i][j] == Neighbors [k]) {
  1710. X            Game->Groups [i][j]= g;
  1711. X            g->NumStones++;
  1712. X        }
  1713. X    }
  1714. X    }
  1715. X    for (k= 0; k < NumNeighbors; k++) {
  1716. X    FreeGroup (Neighbors [k]);
  1717. X    }
  1718. X    CountGrpLibs (Game, ii, jj, c, g, 0);
  1719. X    return g;
  1720. X} /* UniteGroups */
  1721. END_OF_FILE
  1722. if test 12236 -ne `wc -c <'gocapture.c'`; then
  1723.     echo shar: \"'gocapture.c'\" unpacked with wrong size!
  1724. fi
  1725. # end of 'gocapture.c'
  1726. fi
  1727. if test -f 'gocircle.c' -a "${1}" != "-c" ; then 
  1728.   echo shar: Will not clobber existing file \"'gocircle.c'\"
  1729. else
  1730. echo shar: Extracting \"'gocircle.c'\" \(1913 characters\)
  1731. sed "s/^X//" >'gocircle.c' <<'END_OF_FILE'
  1732. X#ifndef lint
  1733. Xstatic char sccsid[]= "@(#)gocircle.c 1.3 87/01/11 Copyr 1986 Sun Micro";
  1734. X#endif
  1735. X
  1736. X/* Copyright (c) Sun MicroSystems, 1986.  This code may be used and modified
  1737. X    for not-for-profit use.  This notice must be retained.  */
  1738. X
  1739. X#include <sunwindow/window_hs.h>
  1740. X
  1741. X
  1742. XDisk (pw, Radius, CtrX, CtrY, Value)
  1743. X    struct pixwin *pw;
  1744. X    int Radius, CtrX, CtrY, Value;
  1745. X{
  1746. Xint x, y, d;
  1747. X    x= 0;
  1748. X    y= Radius;
  1749. X    d= 3 - 2 * Radius;
  1750. X    while (x < y) {
  1751. X    DiskPoints (pw, CtrX, CtrY, x, y, Value);
  1752. X    if (d < 0) d= d + (4 * x) + 6;
  1753. X    else {
  1754. X        d= d + (4 * (x - y)) + 10;
  1755. X        y--;
  1756. X    }
  1757. X    x++;
  1758. X    }
  1759. X    if (x == y) DiskPoints (pw, CtrX, CtrY, x, y, Value);
  1760. X} /* Disk */
  1761. X
  1762. X
  1763. XDiskPoints (pw, CtrX, CtrY, x, y, Color)
  1764. X    struct pixwin *pw;
  1765. X    int CtrX, CtrY, x, y, Color;
  1766. X{
  1767. X    pw_vector (pw, CtrX - x, CtrY - y, CtrX + x, CtrY - y, PIX_SRC, Color);
  1768. X    pw_vector (pw, CtrX - x, CtrY + y, CtrX + x, CtrY + y, PIX_SRC, Color);
  1769. X    pw_vector (pw, CtrX - y, CtrY - x, CtrX + y, CtrY - x, PIX_SRC, Color);
  1770. X    pw_vector (pw, CtrX - y, CtrY + x, CtrX + y, CtrY + x, PIX_SRC, Color);
  1771. X} /* DiskPoints */
  1772. X
  1773. X
  1774. XDiskPR (pr, Radius, CtrX, CtrY, Value)
  1775. X    struct pixrect *pr;
  1776. X    int Radius, CtrX, CtrY, Value;
  1777. X{
  1778. Xint x, y, d;
  1779. X    x= 0;
  1780. X    y= Radius;
  1781. X    d= 3 - 2 * Radius;
  1782. X    while (x < y) {
  1783. X    DiskPointsPR (pr, CtrX, CtrY, x, y, Value);
  1784. X    if (d < 0) d= d + (4 * x) + 6;
  1785. X    else {
  1786. X        d= d + (4 * (x - y)) + 10;
  1787. X        y--;
  1788. X    }
  1789. X    x++;
  1790. X    }
  1791. X    if (x == y) DiskPointsPR (pr, CtrX, CtrY, x, y, Value);
  1792. X} /* DiskPR */
  1793. X
  1794. X
  1795. XDiskPointsPR (pr, CtrX, CtrY, x, y, Color)
  1796. X    struct pixrect *pr;
  1797. X    int CtrX, CtrY, x, y, Color;
  1798. X{
  1799. X    pr_vector (pr, CtrX - x, CtrY - y, CtrX + x, CtrY - y, PIX_SRC, Color);
  1800. X    pr_vector (pr, CtrX - x, CtrY + y, CtrX + x, CtrY + y, PIX_SRC, Color);
  1801. X    pr_vector (pr, CtrX - y, CtrY - x, CtrX + y, CtrY - x, PIX_SRC, Color);
  1802. X    pr_vector (pr, CtrX - y, CtrY + x, CtrX + y, CtrY + x, PIX_SRC, Color);
  1803. X} /* DiskPointsPR */
  1804. END_OF_FILE
  1805. if test 1913 -ne `wc -c <'gocircle.c'`; then
  1806.     echo shar: \"'gocircle.c'\" unpacked with wrong size!
  1807. fi
  1808. # end of 'gocircle.c'
  1809. fi
  1810. if test -f 'gomaster.c' -a "${1}" != "-c" ; then 
  1811.   echo shar: Will not clobber existing file \"'gomaster.c'\"
  1812. else
  1813. echo shar: Extracting \"'gomaster.c'\" \(5799 characters\)
  1814. sed "s/^X//" >'gomaster.c' <<'END_OF_FILE'
  1815. X#ifndef lint
  1816. Xstatic char sccsid[]= "@(#)gomaster.c 1.1 87/01/11 Copyr 1986 Sun Micro";
  1817. X#endif
  1818. X
  1819. X/* Copyright (c) Sun MicroSystems, 1986.  This code may be used and modified
  1820. X    for not-for-profit use.  This notice must be retained.  */
  1821. X
  1822. X#include "goban.h"
  1823. X#include <suntool/panel.h>
  1824. X
  1825. Xextern Panel_item    CurrMoveSlider, HandicapSlider, NameButton;
  1826. X
  1827. X
  1828. XBookMove (i, j, Move, Color, Game)
  1829. X    int i, j;
  1830. X    MoveType *Move;
  1831. X    Stone *Color;
  1832. X    GameType *Game;
  1833. X{
  1834. Xint NumCaptures;
  1835. XStone c;
  1836. X    c= *Color;
  1837. X    AllocMove (i, j, Move);
  1838. X    Game->Board [i] [j]= c;
  1839. X    NewStoneToGroups (Game, i, j);
  1840. X    NumCaptures= GenCaptures (Game, !c, Move);
  1841. X    Game->NumMoves++;
  1842. X    if (c == Black) *Color= White;
  1843. X    else *Color= Black;
  1844. X} /* BookMove */
  1845. X
  1846. X
  1847. XDfltGame (GameName, Game, ShouldPaint)
  1848. X    char *GameName;    GameType *Game;
  1849. X    Panel_setting ShouldPaint;
  1850. X/* Fills in a Game structure with the game from the book "Master of Go"
  1851. X    by Yasunari Kawabata.
  1852. X*/
  1853. X{
  1854. XMoveType *Move;
  1855. XStone Color;
  1856. Xint i, j, NumCaptures;
  1857. X    strcpy (GameName, "masterofgo");
  1858. X    panel_set (NameButton, PANEL_VALUE, GameName, 0);
  1859. X    Game->Grid= 19;
  1860. X    Game->Handicap= 0;
  1861. X    ZeroGame (Game, ShouldPaint);
  1862. X    strncpy (Game->Title, GameName, MaxTitleChars-1);
  1863. X    for (i= 0; i < Game->Grid; i++)
  1864. X    for (j= 0; j < Game->Grid; j++) {
  1865. X        Game->Board [i] [j]= Empty;
  1866. X    }
  1867. X    Game->FirstPlayer= Color= Black;
  1868. X    Game->MoveList= Move= AllocMove (i=16, j=15, (MoveType *) NULL);
  1869. X    Game->Board [i][j]= Color;
  1870. X    NewStoneToGroups (Game, i, j);
  1871. X    NumCaptures= GenCaptures (Game, !Color, Move);
  1872. X    Game->NumMoves++;
  1873. X    Color= White;
  1874. X#define BM(i,j)    BookMove (i, j, Move, &Color, Game); Move= Move->Next
  1875. X    BM (16, 3);
  1876. X    BM (3, 2);
  1877. X    BM (2, 4);
  1878. X    BM (4, 3);
  1879. X    BM (14, 15);
  1880. X    BM (14, 16);
  1881. X    BM (13, 16);
  1882. X    BM (15, 16);
  1883. X    BM (12, 15);
  1884. X    BM (13, 14);
  1885. X    BM (14, 14);
  1886. X    BM (13, 17);
  1887. X    BM (13, 13);
  1888. X    BM (12, 17);
  1889. X    BM (13, 2);
  1890. X    BM (15, 13);
  1891. X    BM (2, 14);
  1892. X    BM (2, 16);
  1893. X    BM (4, 15);
  1894. X    BM (4, 16);
  1895. X    BM (5, 16);
  1896. X    BM (5, 15);
  1897. X    BM (6, 15);
  1898. X    BM (5, 14);
  1899. X    BM (4, 14);
  1900. X    BM (6, 16);
  1901. X    BM (5, 17);
  1902. X    BM (4, 17);
  1903. X    BM (6, 17);
  1904. X    BM (5, 13);
  1905. X    BM (7, 16);
  1906. X    BM (4, 13);
  1907. X    BM (2, 15);
  1908. X    BM (1, 16);
  1909. X    BM (2, 11);
  1910. X    BM (3, 10);
  1911. X    BM (2, 10);
  1912. X    BM (3, 9);
  1913. X    BM (2, 9);
  1914. X    BM (3, 8);
  1915. X    BM (2, 8);
  1916. X    BM (3, 7);
  1917. X    BM (2, 6);
  1918. X    BM (3, 5);
  1919. X    BM (2, 5);
  1920. X    BM (3, 6);
  1921. X    BM (9, 3);
  1922. X    BM (9, 16);
  1923. X    BM (9, 14);
  1924. X    BM (8, 14);
  1925. X    BM (9, 15);
  1926. X    BM (8, 15);
  1927. X    BM (8, 16);
  1928. X    BM (10, 16);
  1929. X    BM (8, 13);
  1930. X    BM (7, 14);
  1931. X    BM (9, 13);
  1932. X    BM (7, 13);
  1933. X    BM (9, 17);
  1934. X    BM (10, 17);
  1935. X    BM (8, 18);
  1936. X    BM (13, 4);
  1937. X    BM (13, 3);
  1938. X    BM (11, 4);
  1939. X    BM (11, 3);
  1940. X    BM (11, 14);
  1941. X    BM (11, 13);
  1942. X    BM (10, 13);
  1943. X    BM (12, 14);
  1944. X    BM (11, 12);
  1945. X    BM (12, 13);
  1946. X    BM (10, 15);
  1947. X    BM (10, 12);
  1948. X    BM (10, 14);
  1949. X    BM (11, 11);
  1950. X    BM (9, 12);
  1951. X    BM (12, 12);
  1952. X    BM (15, 11);
  1953. X    BM (9, 11);
  1954. X    BM (8, 12);
  1955. X    BM (16, 7);
  1956. X    BM (16, 9);
  1957. X    BM (17, 9);
  1958. X    BM (17, 10);
  1959. X    BM (14, 7);
  1960. X    BM (17, 8);
  1961. X    BM (10, 4);
  1962. X    BM (7, 2);
  1963. X    BM (7, 3);
  1964. X    BM (6, 3);
  1965. X    BM (6, 2);
  1966. X    BM (7, 1);
  1967. X    BM (8, 2);
  1968. X    BM (7, 4);
  1969. X    BM (8, 3);
  1970. X    BM (6, 1);
  1971. X    BM (10, 7);
  1972. X    BM (10, 10);
  1973. X    BM (10, 11);
  1974. X    BM (17, 6);
  1975. X    BM (17, 7);
  1976. X    BM (18, 7);
  1977. X    BM (16, 6);
  1978. X    BM (17, 5);
  1979. X    BM (16, 4);
  1980. X    BM (1, 3);
  1981. X    BM (3, 12);
  1982. X    BM (1, 15);
  1983. X    BM (1, 14);
  1984. X    BM (3, 16);
  1985. X    BM (6, 4);
  1986. X    BM (5, 2);
  1987. X    BM (7, 5);
  1988. X    BM (14, 9);
  1989. X    BM (13, 9);
  1990. X    BM (13, 10);
  1991. X    BM (12, 9);
  1992. X    BM (14, 8);
  1993. X    BM (13, 8);
  1994. X    BM (7, 15);
  1995. X    BM (7, 17);
  1996. X    BM (16, 5);
  1997. X    BM (15, 5);
  1998. X    BM (18, 3);
  1999. X    BM (17, 2);
  2000. X    BM (12, 10);
  2001. X    BM (11, 10);
  2002. X    BM (13, 7);
  2003. X    BM (17, 4);
  2004. X    BM (13, 6);
  2005. X    BM (14, 6);
  2006. X    BM (11, 9);
  2007. X    BM (12, 8);
  2008. X    BM (11, 8);
  2009. X    BM (12, 7);
  2010. X    BM (11, 7);
  2011. X    BM (12, 6);
  2012. X    BM (11, 6);
  2013. X    BM (12, 5);
  2014. X    BM (11, 5);
  2015. X    BM (12, 4);
  2016. X    BM (9, 9);
  2017. X    BM (8, 1);
  2018. X    BM (18, 4);
  2019. X    BM (18, 2);
  2020. X    BM (18, 6);
  2021. X    BM (1, 4);
  2022. X    BM (1, 2);
  2023. X    BM (8, 8);
  2024. X    BM (8, 9);
  2025. X    BM (7, 9);
  2026. X    BM (8, 10);
  2027. X    BM (9, 8);
  2028. X    BM (7, 7);
  2029. X    BM (7, 8);
  2030. X    BM (5, 4);
  2031. X    BM (6, 5);
  2032. X    BM (6, 7);
  2033. X    BM (8, 7);
  2034. X    BM (2, 7);
  2035. X    BM (1, 7);
  2036. X    BM (13, 11);
  2037. X    BM (12, 11);
  2038. X    BM (16, 8);
  2039. X    BM (14, 12);
  2040. X    BM (15, 12);
  2041. X    BM (4, 18);
  2042. X    BM (3, 18);
  2043. X    BM (5, 18);
  2044. X    BM (1, 18);
  2045. X    BM (7, 6);
  2046. X    BM (8, 0);
  2047. X    BM (9, 0);
  2048. X    BM (7, 0);
  2049. X    BM (9, 1);
  2050. X    BM (0, 14);
  2051. X    BM (0, 13);
  2052. X    BM (0, 15);
  2053. X    BM (2, 13);
  2054. X    BM (15, 7);
  2055. X    BM (15, 6);
  2056. X    BM (15, 8);
  2057. X    BM (13, 5);
  2058. X    BM (5, 6);
  2059. X    BM (5, 5);
  2060. X    BM (4, 5);
  2061. X    BM (0, 4);
  2062. X    BM (10, 6);
  2063. X    BM (9, 6);
  2064. X    BM (5, 8);
  2065. X    BM (3, 4);
  2066. X    BM (4, 4);
  2067. X    BM (7, 10);
  2068. X    BM (8, 11);
  2069. X    BM (5, 9);
  2070. X    BM (3, 15);
  2071. X    BM (4, 9);
  2072. X    BM (4, 8);
  2073. X    BM (3, 14);
  2074. X    BM (1, 12);
  2075. X    BM (1, 13);
  2076. X    BM (2, 12);
  2077. X    BM (1, 11);
  2078. X    BM (3, 13);
  2079. X    BM (0, 12);
  2080. X    BM (3, 11);
  2081. X    BM (5, 11);
  2082. X    BM (4, 11);
  2083. X    BM (2, 12);
  2084. X    BM (5, 10);
  2085. X    BM (6, 10);
  2086. X    BM (4, 10);
  2087. X    BM (10, 8);
  2088. X    BM (10, 9);
  2089. X    BM (6, 12);
  2090. X    BM (10, 18);
  2091. X    BM (9, 18);
  2092. X    BM (10, 5);
  2093. X    BM (9, 5);
  2094. X    BM (6, 9);
  2095. X    BM (6, 8);
  2096. X    BM (5, 9);
  2097. X    BM (6, 6);
  2098. X    BM (5, 7);
  2099. X    BM (0, 3);
  2100. X    BM (0, 2);
  2101. X    BM (2, 3);
  2102. X    BM (2, 2);
  2103. X    BM (14, 11);
  2104. X    BM (14, 10);
  2105. X    BM (15, 14);
  2106. X    BM (16, 14);
  2107. X    BM (13, 15);
  2108. X    BM (18, 8);
  2109. X    BM (11, 16);
  2110. X    BM (11, 17);
  2111. X    SetFirstPlayerButton (Color, ShouldPaint);
  2112. X    Game->MoveNum= Game->NumMoves;
  2113. X    panel_set (CurrMoveSlider
  2114. X    , PANEL_MAX_VALUE, Game->NumMoves
  2115. X    , PANEL_VALUE, Game->MoveNum
  2116. X    , PANEL_PAINT, ShouldPaint, 0);
  2117. X    panel_set (HandicapSlider, PANEL_VALUE, Game->Handicap
  2118. X    , PANEL_PAINT, ShouldPaint, 0);
  2119. X    if (Game->MoveList != NULL) Game->CurrMove= Move;
  2120. X    return 0;
  2121. X} /* DfltGame */
  2122. END_OF_FILE
  2123. if test 5799 -ne `wc -c <'gomaster.c'`; then
  2124.     echo shar: \"'gomaster.c'\" unpacked with wrong size!
  2125. fi
  2126. # end of 'gomaster.c'
  2127. fi
  2128. if test -f 'gopanel.c' -a "${1}" != "-c" ; then 
  2129.   echo shar: Will not clobber existing file \"'gopanel.c'\"
  2130. else
  2131. echo shar: Extracting \"'gopanel.c'\" \(17631 characters\)
  2132. sed "s/^X//" >'gopanel.c' <<'END_OF_FILE'
  2133. X#ifndef lint
  2134. Xstatic char sccsid[]= "@(#)gopanel.c 1.3 87/01/11 Copyr 1986 Sun Micro";
  2135. X#endif
  2136. X
  2137. X/* Copyright (c) Sun MicroSystems, 1986.  This code may be used and modified
  2138. X    for not-for-profit use.  This notice must be retained.  */
  2139. X
  2140. X#include "goban.h"
  2141. X#include <suntool/canvas.h>
  2142. X#include <suntool/panel.h>
  2143. X#include <suntool/textsw.h>
  2144. X#include <suntool/fullscreen.h>
  2145. X
  2146. X
  2147. Xstruct pixrect    *MovingImage, *PlacingImage;
  2148. Xchar StdMessage [] =
  2149. X"Left:  new branch.  Ctrl left:  place.  Center:  Backup.  Right:  Step.";
  2150. X
  2151. Xextern Canvas        BoardSW;
  2152. Xextern Panel_item    CurrMoveSlider;
  2153. Xextern Panel_item    FirstPlayerButton;
  2154. Xextern Panel_item    HandicapSlider;
  2155. Xextern Panel_item    LabelButton;
  2156. Xextern Panel        MainPanel;
  2157. Xextern Panel_item    MsgPanelItem;
  2158. Xextern Panel_item    NameButton;
  2159. Xextern Panel_item    PlaceMoveButton;
  2160. Xextern Panel_item    StatusPanelItem;
  2161. Xextern Textsw        TextSW;
  2162. Xextern int        UserTextMods;
  2163. Xextern int        Verbose;
  2164. X
  2165. Xextern    SaveText ();
  2166. X
  2167. X/* Forward */
  2168. XAltProc ();
  2169. XCloseProc ();
  2170. XFirstPlayProc ();
  2171. XHandicapProc ();
  2172. XLeafwardNotify ();
  2173. XPanel_setting    MoveLabelNotify ();
  2174. XPassProc ();
  2175. XPlaceMoveProc ();
  2176. XPrintProc ();
  2177. XPruneProc ();
  2178. XQuit ();
  2179. XReadGameProc ();
  2180. XReplayProc ();
  2181. XResetProc ();
  2182. XRootwardNotify ();
  2183. XSetCurrMove ();
  2184. XVerboseNotify ();
  2185. XWriteBoardProc ();
  2186. XWriteGameProc ();
  2187. X
  2188. X
  2189. XAltProc (PI, GoEvent)
  2190. X    Panel_item PI;
  2191. X    struct inputevent *GoEvent;
  2192. X{
  2193. XGameType    *Game;
  2194. XMoveType    *m;
  2195. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2196. X    if ((Game->CurrMove != NULL) && (Game->CurrMove->AltNext != NULL)) {
  2197. X    Sideways (Game, 1);
  2198. X    }
  2199. X} /* AltProc */
  2200. X
  2201. X
  2202. XCloseProc (PI, GoEvent)
  2203. X    Panel_item PI;
  2204. X    struct inputevent *GoEvent;
  2205. X/* Close tool to icon state. */
  2206. X{
  2207. X    wmgr_close (window_get (GoFrame, WIN_FD), RootFD);
  2208. X} /* CloseProc */
  2209. X
  2210. X
  2211. X    int
  2212. XConfirm ()
  2213. X{
  2214. Xstruct fullscreen    *FullScreen;
  2215. Xstruct inputmask    im;
  2216. Xstruct inputevent    ie;
  2217. Xint            result;
  2218. Xint            FD;
  2219. X    Msg ("Confirm:  right mouse button.  Deny: left & center buttons.");
  2220. X    FD= (int) window_get (MainPanel, WIN_FD);
  2221. X    FullScreen= (struct fullscreen *) fullscreen_init (FD);
  2222. X    input_imnull (&im);
  2223. X    win_setinputcodebit (&im, MS_LEFT);
  2224. X    win_setinputcodebit (&im, MS_MIDDLE);
  2225. X    win_setinputcodebit (&im, MS_RIGHT);
  2226. X    win_setinputmask (FD, &im, (struct inputmask *) NULL, WIN_NULLLINK);
  2227. X    for (;;) {    /* improve this do loop to eliminate for (;;). */
  2228. X    if (input_readevent (FD, &ie) == -1)  {
  2229. X        perror("Confirm input failed.");
  2230. X        abort ();
  2231. X    }
  2232. X    switch (ie.ie_code)  {
  2233. X     case MS_LEFT:         result = FALSE; break;
  2234. X     case MS_MIDDLE:       result = FALSE; break;
  2235. X     case MS_RIGHT:        result = TRUE;  break;
  2236. X     default:              continue;
  2237. X    }
  2238. X    break;
  2239. X    }
  2240. X    fullscreen_destroy (FullScreen);
  2241. X    StdMsg ();
  2242. X    return result;
  2243. X} /* Confirm */
  2244. X
  2245. X
  2246. XFirstPlayProc (PI, GoEvent)
  2247. X    Panel_item PI;
  2248. X    struct inputevent *GoEvent;
  2249. X/* Toggles first player of game. */
  2250. X{
  2251. XGameType *Game;
  2252. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2253. X    if (Game->NumMoves == 0) SetFirst (Game, !Game->FirstPlayer, PANEL_CLEAR);
  2254. X} /* FirstPlayProc */
  2255. X
  2256. X
  2257. X    struct pixrect *
  2258. XGenStoneImage (p, Color)
  2259. X    struct pixrect *p;
  2260. X    int Color;
  2261. X{
  2262. Xint Width, Height, LineWid;
  2263. Xint i;
  2264. X    if (p != NULL) free (p);
  2265. X    Width= 25;
  2266. X    Height= 25;
  2267. X    LineWid= 2;
  2268. X    p= mem_create (Width, Height, 1);
  2269. X    for (i= 0; i < LineWid; i++) {
  2270. X    pr_vector (p, 0, Height/2 + i, Width, Height/2 + i, PIX_SRC, 1);
  2271. X    pr_vector (p, Width/2 + i, 0, Width/2 +i, Height, PIX_SRC, 1);
  2272. X    }
  2273. X    DiskPR (p, Width / 3, Width / 2, Width / 2, 1);
  2274. X    if (Color == White) DiskPR (p, Width/3 - LineWid, Width/2, Width/2, 0);
  2275. X    return p;
  2276. X} /* GenStoneImage */
  2277. X
  2278. X
  2279. XHandicapProc (PI, Value, GoEvent)
  2280. X    Panel_item PI;
  2281. X    unsigned int Value;
  2282. X    struct inputevent *GoEvent;
  2283. X/* Sets handicap for game. */
  2284. X{
  2285. XGameType *Game;
  2286. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2287. X    SetHandicap (Game, (int) Value);
  2288. X} /* HandicapProc */
  2289. X
  2290. X
  2291. XInitPanel (Game, GameName, MsgSW, StatusSW)
  2292. X    GameType    *Game;
  2293. X    char    *GameName;
  2294. X    Panel    MsgSW, StatusSW;
  2295. X{
  2296. XPanel_item    Junk;
  2297. X#define NullFont    (struct pixfont *) NULL
  2298. X    BlackFirstImage= GenStoneImage (BlackFirstImage, Black);
  2299. X    WhiteFirstImage= GenStoneImage (WhiteFirstImage, White);
  2300. X    FirstPlayerButton= panel_create_item (MainPanel, PANEL_CHOICE
  2301. X    , PANEL_DISPLAY_LEVEL,    PANEL_CURRENT
  2302. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2303. X    , PANEL_NOTIFY_PROC,    FirstPlayProc
  2304. X    , PANEL_LABEL_STRING,    "Next: "
  2305. X    , PANEL_CHOICE_IMAGES,    BlackFirstImage, WhiteFirstImage, 0
  2306. X    , PANEL_PAINT,        PANEL_NONE
  2307. X    , 0);    /* Remove PANEL_PAINT line in 3.0. */
  2308. X    MovingImage= panel_button_image (MainPanel, "Moving", 8, NullFont);
  2309. X    PlacingImage= panel_button_image (MainPanel, "Placing", 9, NullFont);
  2310. X    PlaceMoveButton= panel_create_item (MainPanel, PANEL_CHOICE
  2311. X    , PANEL_DISPLAY_LEVEL,    PANEL_CURRENT
  2312. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2313. X    , PANEL_NOTIFY_PROC,    PlaceMoveProc
  2314. X    , PANEL_CHOICE_IMAGES,    PlacingImage, MovingImage, 0
  2315. X    , PANEL_VALUE,        1
  2316. X    , 0);
  2317. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2318. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2319. X    , PANEL_NOTIFY_PROC,    PassProc
  2320. X    , PANEL_LABEL_IMAGE, panel_button_image (MainPanel, "Pass", 6, NullFont)
  2321. X    , 0);
  2322. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2323. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2324. X    , PANEL_NOTIFY_PROC,    ReplayProc
  2325. X    , PANEL_LABEL_IMAGE
  2326. X        , panel_button_image (MainPanel, "Replay", 8, NullFont)
  2327. X    , 0);
  2328. X/*    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2329. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2330. X    , PANEL_NOTIFY_PROC,    AltProc
  2331. X    , PANEL_LABEL_IMAGE, panel_button_image (MainPanel, "Alt", 5, NullFont)
  2332. X    , 0);
  2333. X*/
  2334. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2335. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2336. X    , PANEL_NOTIFY_PROC,    PruneProc
  2337. X    , PANEL_LABEL_IMAGE
  2338. X        , panel_button_image (MainPanel, "Prune", 7, NullFont)
  2339. X    , 0);
  2340. X#ifdef LABEL_BUTTON
  2341. X    LabelButton= panel_create_item (MainPanel, PANEL_TEXT
  2342. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2343. X    , PANEL_VALUE,        NULL
  2344. X    , PANEL_VALUE_DISPLAY_LENGTH,    MaxMvLblChars-1
  2345. X    , PANEL_LABEL_STRING,    "Label: "
  2346. X    , PANEL_NOTIFY_LEVEL,    PANEL_ALL
  2347. X    , PANEL_NOTIFY_PROC,    MoveLabelNotify
  2348. X    , 0);
  2349. X#endif LABEL_BUTTON
  2350. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2351. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2352. X    , PANEL_VALUE,        GameName
  2353. X    , PANEL_NOTIFY_PROC,    RootwardNotify
  2354. X    , PANEL_LABEL_IMAGE
  2355. X        , panel_button_image (MainPanel, "Rootward", 10, NullFont)
  2356. X    , 0);
  2357. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2358. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2359. X    , PANEL_VALUE,        GameName
  2360. X    , PANEL_NOTIFY_PROC,    LeafwardNotify
  2361. X    , PANEL_LABEL_IMAGE
  2362. X        , panel_button_image (MainPanel, "Leafward", 10, NullFont)
  2363. X    , 0);
  2364. X    CurrMoveSlider= panel_create_item (MainPanel, PANEL_SLIDER
  2365. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2366. X    , PANEL_NOTIFY_PROC,    SetCurrMove
  2367. X    , PANEL_MAX_VALUE,    MaxMoves
  2368. X    , PANEL_VALUE,        Game->NumMoves
  2369. X    , PANEL_LAYOUT,        PANEL_VERTICAL
  2370. X    , PANEL_SLIDER_WIDTH,    250
  2371. X    , PANEL_LABEL_STRING,    "Current Move: "
  2372. X    , 0);
  2373. X    HandicapSlider= panel_create_item (MainPanel, PANEL_SLIDER
  2374. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2375. X    , PANEL_NOTIFY_PROC,    HandicapProc
  2376. X    , PANEL_MAX_VALUE,    MaxHandicap
  2377. X    , PANEL_VALUE,        Game->Handicap
  2378. X    , PANEL_LAYOUT,        PANEL_VERTICAL
  2379. X    , PANEL_LABEL_STRING,    "Handicap: "
  2380. X    , PANEL_PAINT,        PANEL_NONE
  2381. X    , 0);    /* Remove PANEL_PAINT line in 3.0. */
  2382. X    NameButton= panel_create_item (MainPanel, PANEL_TEXT
  2383. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2384. X    , PANEL_VALUE,        GameName
  2385. X    , PANEL_VALUE_DISPLAY_LENGTH,    16
  2386. X    , PANEL_LABEL_STRING,    "Game: "
  2387. X    , 0);
  2388. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2389. X    , PANEL_CLIENT_DATA,    (caddr_t) NameButton
  2390. X    , PANEL_NOTIFY_PROC,    ReadGameProc
  2391. X    , PANEL_VALUE,        GameName
  2392. X    , PANEL_LABEL_IMAGE,
  2393. X        panel_button_image (MainPanel, "Read Game", 11, NullFont)
  2394. X    , 0);
  2395. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2396. X    , PANEL_CLIENT_DATA,    (caddr_t) NameButton
  2397. X    , PANEL_NOTIFY_PROC,    PrintProc
  2398. X    , PANEL_VALUE,        GameName
  2399. X    , PANEL_LABEL_IMAGE
  2400. X        , panel_button_image (MainPanel, "Print", 7, NullFont)
  2401. X    , 0);
  2402. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2403. X    , PANEL_CLIENT_DATA,    (caddr_t) NameButton
  2404. X    , PANEL_VALUE,        GameName
  2405. X    , PANEL_NOTIFY_PROC,    WriteGameProc
  2406. X    , PANEL_LABEL_IMAGE,
  2407. X        panel_button_image (MainPanel, "Write Game", 12, NullFont)
  2408. X    , 0);
  2409. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2410. X    , PANEL_CLIENT_DATA,    (caddr_t) NameButton
  2411. X    , PANEL_VALUE,        GameName
  2412. X    , PANEL_NOTIFY_PROC,    WriteBoardProc
  2413. X    , PANEL_LABEL_IMAGE,
  2414. X        panel_button_image (MainPanel, "Write Board", 13, NullFont)
  2415. X    , 0);
  2416. X    Junk= panel_create_item (MainPanel, PANEL_CHOICE
  2417. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2418. X    , PANEL_NOTIFY_PROC,    VerboseNotify
  2419. X    , PANEL_CHOICE_STRINGS,    "Verbose", "Silent", 0
  2420. X    , PANEL_VALUE,        Verbose
  2421. X    , PANEL_DISPLAY_LEVEL,    PANEL_CURRENT
  2422. X    , 0);
  2423. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2424. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2425. X    , PANEL_NOTIFY_PROC,    CloseProc
  2426. X    , PANEL_LABEL_IMAGE
  2427. X        , panel_button_image (MainPanel, "Close", 7, NullFont)
  2428. X    , 0);
  2429. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2430. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2431. X    , PANEL_NOTIFY_PROC,    Quit
  2432. X    , PANEL_LABEL_IMAGE, panel_button_image (MainPanel, "Quit", 6, NullFont)
  2433. X    , 0);
  2434. X    Junk= panel_create_item (MainPanel, PANEL_BUTTON
  2435. X    , PANEL_CLIENT_DATA,    (caddr_t) Game
  2436. X    , PANEL_NOTIFY_PROC,    ResetProc
  2437. X    , PANEL_LABEL_IMAGE
  2438. X        , panel_button_image (MainPanel, "Reset", 7, NullFont)
  2439. X    , 0);
  2440. X    MsgPanelItem= panel_create_item (MsgSW, PANEL_MESSAGE
  2441. X    , PANEL_LABEL_STRING, StdMessage, 0);
  2442. X    StatusPanelItem= panel_create_item (StatusSW, PANEL_MESSAGE, 0);
  2443. X} /* InitPanel */
  2444. X
  2445. X
  2446. XLabelToPanel (m)
  2447. X    MoveType *m;
  2448. X{
  2449. Xchar *c;
  2450. X    if (m == NULL) c= " ";
  2451. X    else c= m->Label;
  2452. X    panel_set (LabelButton, PANEL_VALUE, c, 0);
  2453. X} /* LabelToPanel */
  2454. X
  2455. X
  2456. XLeafwardNotify (PI, event)
  2457. X    Panel_item    PI;
  2458. X    Event    *event;
  2459. X{
  2460. XGameType *Game;
  2461. XMoveType *Move;
  2462. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2463. X    if (UserTextMods) SaveText (Game);
  2464. X    Step (Game, 0);
  2465. X    if (Game->CurrMove == NULL) return;
  2466. X    for (Move= Game->CurrMove->Next; Move != NULL; Move= Move->Next) {
  2467. X    if (Move->AltNext != Move) break;
  2468. X    Step (Game, 0);
  2469. X    }
  2470. X    Replay (Game, 1);
  2471. X} /* LeafwardNotify */
  2472. X
  2473. X
  2474. X    Panel_setting
  2475. XMoveLabelNotify (PI, GoEvent)
  2476. X    Panel_item    PI;
  2477. X    Event    *GoEvent;
  2478. X{
  2479. XGameType *Game;
  2480. Xchar    c, s [2];
  2481. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2482. X    if (Game->CurrMove != NULL) {
  2483. X    c= event_id (GoEvent);
  2484. X    s[0]= c;
  2485. X    s[1]= '\0';
  2486. X    if ((c == '\127') || (c == '\010')) c= '\0'; /* del or back-space */
  2487. X    if ((c == '\0')
  2488. X     || ((c >= 'a') && (c <= 'z'))
  2489. X     || ((c >= 'A') && (c <= 'Z')))
  2490. X        panel_set_value (PI, s);
  2491. X    PanelToLabel (Game->CurrMove->Next);
  2492. X    DrawAlts (Game, Game->CurrMove);
  2493. X    }
  2494. X    return panel_text_notify (PI, GoEvent);
  2495. X} /* MoveLabelNotify */
  2496. X
  2497. X
  2498. XMsg (MsgString)
  2499. X    char *MsgString;
  2500. X{
  2501. X    panel_set (MsgPanelItem, PANEL_LABEL_STRING, MsgString, 0);
  2502. X} /* MsgString */
  2503. X
  2504. X
  2505. XPanelToLabel (m)
  2506. X    MoveType *m;
  2507. X{
  2508. X#ifdef LABEL_BUTTON
  2509. Xchar *s;
  2510. X    if (m == NULL) return;
  2511. X    s= (char *) panel_get (LabelButton, PANEL_VALUE);
  2512. X/*    printf ("PL %s:  %s\n", s, m->Note);
  2513. X*/
  2514. X    m->Label [0]= *s;
  2515. X    m->Label [1]= '\0';
  2516. X#endif LABEL_BUTTON
  2517. X} /* PanelToLabel */
  2518. X
  2519. X
  2520. XPassProc (PI, GoEvent)
  2521. X    Panel_item PI;
  2522. X    struct inputevent *GoEvent;
  2523. X/* Allows a player to pass on a move. */
  2524. X{
  2525. XGameType *Game;
  2526. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2527. X    if (EnterMove (-1, -1, Game, 1, PassAction)) StatusMsg ("Unable to pass.");
  2528. X} /* PassProc */
  2529. X
  2530. X
  2531. XPlaceMoveProc (PI, GoEvent)
  2532. X    Panel_item PI;
  2533. X    struct inputevent *GoEvent;
  2534. X/* Toggles Placing or Moving state and Panel button. */
  2535. X{
  2536. XGameType *Game;
  2537. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2538. X    if (Game->Placing == 0) {
  2539. X    if (Game->MoveNum == 0) {
  2540. X        Game->Placing= 1;
  2541. X        panel_set_value (PlaceMoveButton, 0);
  2542. X    }
  2543. X    } else {
  2544. X    Game->Placing= 0;
  2545. X    panel_set_value (PlaceMoveButton, 1);
  2546. X    }
  2547. X} /* PlaceMoveProc */
  2548. X
  2549. X
  2550. XPrintProc (PI, GoEvent)
  2551. X    Panel_item PI;
  2552. X    struct inputevent *GoEvent;
  2553. X{
  2554. XGameType *Game;
  2555. X    PI= panel_get (PI, PANEL_CLIENT_DATA);
  2556. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2557. X    PrintBoard (Game);
  2558. X} /* PrintProc */
  2559. X
  2560. X
  2561. XPruneProc (PI, GoEvent)
  2562. X    Panel_item PI;
  2563. X    struct inputevent *GoEvent;
  2564. X{
  2565. XGameType *Game;
  2566. XMoveType *m, *m1;
  2567. Xint Count;
  2568. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2569. X    m= Game->CurrMove;
  2570. X    if (m == NULL) return;
  2571. X    if (m->AltNext == m) {
  2572. X    if (m->Prev) m->Prev->Next= NULL;
  2573. X    else Game->MoveList= NULL;
  2574. X    } else {
  2575. X    if (!m->Prev) {
  2576. X        Game->MoveList= m->AltNext;
  2577. X    } else {
  2578. X        m->Prev->Next= m->AltNext;
  2579. X    }
  2580. X    if (m->AltNext->AltNext == m) {
  2581. X        m->AltNext->Label [0]= ' ';
  2582. X    } else {
  2583. X        for (m1= m->AltNext, Count= 0; m1 != m; m1= m1->AltNext)
  2584. X        m1->Label [0]= 'a' + Count++;
  2585. X    }
  2586. X    m->AltNext->AltPrev= m->AltPrev;
  2587. X    m->AltPrev->AltNext= m->AltNext;
  2588. X    }
  2589. X    m->AltNext= NULL;
  2590. X    m->AltPrev= NULL;
  2591. X    Backup (Game, 1);
  2592. X    FreeMoves (m);
  2593. X    Step (Game, 1);
  2594. X} /* PruneProc */
  2595. X
  2596. X
  2597. XQuit (PI, GoEvent)
  2598. X    Panel_item PI;
  2599. X    struct inputevent *GoEvent;
  2600. X{
  2601. X    if (Confirm ()) exit (0);
  2602. X} /* Quit */
  2603. X
  2604. X
  2605. XReadGameProc (PI, GoEvent)
  2606. X    Panel_item PI;
  2607. X    struct inputevent *GoEvent;
  2608. X/* Notified by panel. */
  2609. X{
  2610. XGameType *Game;
  2611. X    if (Confirm ()) {
  2612. X    PI= panel_get (PI, PANEL_CLIENT_DATA);
  2613. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2614. X    if (ReadGame (panel_get_value (PI), Game, PANEL_CLEAR)) {
  2615. X        StatusMsg ("Can't read file.");
  2616. X        return;
  2617. X    }
  2618. X    Replay (Game, 1);
  2619. X    Status (Game);
  2620. X    }
  2621. X} /* ReadGameProc */
  2622. X
  2623. X
  2624. XReplayProc (PI, GoEvent)
  2625. X    Panel_item PI;
  2626. X    struct inputevent *GoEvent;
  2627. X{
  2628. XGameType *Game;
  2629. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2630. X    Replay (Game, 1);    /* Recompute board. */
  2631. X} /* ReplayProc */
  2632. X
  2633. X
  2634. XResetProc (PI, GoEvent)
  2635. X    Panel_item PI;
  2636. X    struct inputevent *GoEvent;
  2637. X/* Resets (clears) game. */
  2638. X{
  2639. Xstruct rect *r;
  2640. XGameType *Game;
  2641. X    if (Confirm ()) {
  2642. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2643. X    r= (struct rect *) window_get (BoardSW, WIN_RECT);
  2644. X    pw_writebackground (BoardPW, 0, 0, r->r_width, r->r_height, PIX_CLR);
  2645. X    ZeroGame (Game, PANEL_CLEAR);
  2646. X    HandicapBoard (Game);
  2647. X/*
  2648. X    DrawGameInit (Game, r->r_width, r->r_height);
  2649. X*/
  2650. X    DrawGame (Game, 0);
  2651. X    }
  2652. X} /* ResetProc */
  2653. X
  2654. X
  2655. XRootwardNotify (PI, event)
  2656. X    Panel_item    PI;
  2657. X    Event    *event;
  2658. X{
  2659. XGameType *Game;
  2660. XMoveType *Move;
  2661. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2662. X    if (UserTextMods) SaveText (Game);
  2663. X    Backup (Game, 0);
  2664. X    if (Game->CurrMove == NULL) return;
  2665. X    for (Move= Game->CurrMove; Move != NULL; Move= Move->Prev) {
  2666. X    if (Move->Next->AltNext != Move->Next) break;
  2667. X    Backup (Game, 0);
  2668. X    }
  2669. X    Replay (Game, 1);
  2670. X} /* RootwardNotify */
  2671. X
  2672. X
  2673. XSetCurrMove (PI, Value, GoEvent)
  2674. X    Panel_item PI;
  2675. X    unsigned int Value;
  2676. X    struct inputevent *GoEvent;
  2677. X{
  2678. XMoveType *m;
  2679. Xint k;
  2680. XGameType *Game;
  2681. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2682. X    if (Value > Game->NumMoves) Game->MoveNum= Game->NumMoves;
  2683. X    else Game->MoveNum= Value;
  2684. X    for (m= Game->MoveList, k= 1; m != NULL; m= m->Next) {
  2685. X    /* Find move corresponding to MoveNum. */
  2686. X/*
  2687. X    if (m->Next == NULL) break;
  2688. X    if (k >= Game->MoveNum) break;
  2689. X    k++;
  2690. X*/
  2691. X    }
  2692. X    if (Game->MoveNum == 0) Game->CurrMove= NULL;
  2693. X    else Game->CurrMove= m;
  2694. X    Replay (Game, 1);
  2695. X    Status (Game);
  2696. X} /* SetCurrMove */
  2697. X
  2698. X
  2699. XSetFirstPlayerButton (s, ShouldPaint)
  2700. X    Stone s;
  2701. X    Panel_setting ShouldPaint;
  2702. X{
  2703. X    if (s == Black)
  2704. X    panel_set (FirstPlayerButton, PANEL_VALUE, 0
  2705. X        , PANEL_PAINT, ShouldPaint, 0);
  2706. X    else
  2707. X    panel_set (FirstPlayerButton, PANEL_VALUE, 1
  2708. X        , PANEL_PAINT, ShouldPaint, 0);
  2709. X} /* SetFirstPlayerButton */
  2710. X
  2711. X
  2712. XStatus (Game)
  2713. X    GameType *Game;
  2714. X{
  2715. Xchar    MsgString [80];
  2716. Xchar    AltMsg [30];
  2717. Xint    i;
  2718. XMoveType *m;
  2719. X    panel_set (CurrMoveSlider, PANEL_VALUE, Game->MoveNum, 0);
  2720. X    for (m= Game->CurrMove, i= 1; m != NULL; m= m->AltNext) {
  2721. X    if (m->AltNext == Game->CurrMove) break;
  2722. X    i++;
  2723. X    }
  2724. X    if (i > 1) sprintf (AltMsg, "%d Alternates.  ", i);
  2725. X    else AltMsg [0]= '\0';
  2726. X    sprintf (MsgString
  2727. X    , "%sWhite stones captured %d,  Black stones captured %d.\n"
  2728. X    , AltMsg
  2729. X    , Game->Prisoners [White], Game->Prisoners [Black]);
  2730. X    StatusMsg (MsgString);
  2731. X} /* Status */
  2732. X
  2733. X
  2734. XStatusMsg (MsgString)
  2735. X    char *MsgString;
  2736. X/* Status message in panel message subwindow. */
  2737. X{
  2738. X    panel_set (StatusPanelItem, PANEL_LABEL_STRING, MsgString, 0);
  2739. X} /* StatusMsg */
  2740. X
  2741. X
  2742. XStdMsg ()
  2743. X/* Standard message in panel message subwindow. */
  2744. X{
  2745. X    Msg (StdMessage);
  2746. X} /* StdMsg */
  2747. X
  2748. X
  2749. XVerboseNotify (PI, Value, GoEvent)
  2750. X    Panel_item    PI;
  2751. X    int        Value;
  2752. X    Event    *GoEvent;
  2753. X{
  2754. XGameType *Game;
  2755. Xint i, j;
  2756. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2757. X    Verbose= Value;
  2758. X    if (Verbose) {
  2759. X    if (Game->CurrMove) {
  2760. X        HighlightMove (Game, Game->CurrMove, -1, -1);
  2761. X        if (Game->CurrMove->Next) DrawAlts (Game, Game->CurrMove);
  2762. X    }
  2763. X    textsw_normalize_view (TextSW, 0);
  2764. X    } else {
  2765. X    if (Game->CurrMove) {
  2766. X        if (Game->CurrMove->Next) DrawAltsEmpty (Game, Game->CurrMove);
  2767. X        i= Game->CurrMove->i;    /* Unhighlight currmove. */
  2768. X        j= Game->CurrMove->j;
  2769. X        UnHighlightMove (Game, i, j);
  2770. X    }
  2771. X    textsw_normalize_view (TextSW, TEXTSW_INFINITY);
  2772. X    }
  2773. X} /* VerboseNotify */
  2774. X
  2775. X
  2776. XWriteBoardProc (PI, GoEvent)
  2777. X    Panel_item PI;
  2778. X    struct inputevent *GoEvent;
  2779. X/* Notified by panel. */
  2780. X{
  2781. XGameType *Game;
  2782. X    if (Confirm ()) {
  2783. X    PI= panel_get (PI, PANEL_CLIENT_DATA);
  2784. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2785. X    if (WriteBoard (panel_get_value (PI), Game))
  2786. X        StatusMsg ("Can't create file.");
  2787. X    }
  2788. X} /* WriteBoardProc */
  2789. X
  2790. X
  2791. XWriteGameProc (PI, GoEvent)
  2792. X    Panel_item PI;
  2793. X    struct inputevent *GoEvent;
  2794. X/* Notified by panel. */
  2795. X{
  2796. XGameType *Game;
  2797. X    if (Confirm ()) {
  2798. X    PI= panel_get (PI, PANEL_CLIENT_DATA);
  2799. X    Game= (GameType *) panel_get (PI, PANEL_CLIENT_DATA);
  2800. X    if (UserTextMods) SaveText (Game);
  2801. X    if (WriteGame (panel_get_value (PI), Game))
  2802. X        StatusMsg ("Can't create file.");
  2803. X    }
  2804. X} /* WriteGameProc */
  2805. END_OF_FILE
  2806. if test 17631 -ne `wc -c <'gopanel.c'`; then
  2807.     echo shar: \"'gopanel.c'\" unpacked with wrong size!
  2808. fi
  2809. # end of 'gopanel.c'
  2810. fi
  2811. if test -f 'goprint.c' -a "${1}" != "-c" ; then 
  2812.   echo shar: Will not clobber existing file \"'goprint.c'\"
  2813. else
  2814. echo shar: Extracting \"'goprint.c'\" \(5030 characters\)
  2815. sed "s/^X//" >'goprint.c' <<'END_OF_FILE'
  2816. X#ifndef lint
  2817. Xstatic char sccsid[]= "@(#)goprint.c 1.3 87/01/11 Copyr 1986 Sun Micro";
  2818. X#endif
  2819. X
  2820. X/* Copyright (c) Sun MicroSystems, 1985.  This code may be used and modified
  2821. X    for not-for-profit use.  This notice must be retained.  */
  2822. X
  2823. X
  2824. X#include "goban.h"
  2825. X#include <setjmp.h>
  2826. X
  2827. Xjmp_buf LWEnvironment;
  2828. X
  2829. X
  2830. XPrintBoard (Game)
  2831. X    GameType *Game;
  2832. X/* Print board large. */
  2833. X{
  2834. XFILE *f;
  2835. Xint i, j, k, LastLine;
  2836. XMoveType *Move;
  2837. Xint Diam;    /* Diameter of a stone. */
  2838. Xint Units;    /* Units per inch. */
  2839. Xint FontPts;
  2840. Xint BrdMargin, Margin, PageWidth;
  2841. XStone s;
  2842. X    LastLine= Game->Grid - 1;
  2843. X    Units= 72;    /* Pts. per inch. */
  2844. X    FontPts= 12;
  2845. X    BrdMargin= (int) (1.5 * Units);
  2846. X    Margin= Units;
  2847. X    PageWidth= (int) (8.5 * Units);
  2848. X    Diam= ((int) (Units * 5.5)) / LastLine;
  2849. X    if (setjmp (LWEnvironment)) {
  2850. X    StatusMsg ("SigPipe: Couldn't find laser printer (lpr -Plw).\n");
  2851. X    return 1;
  2852. X    } else {
  2853. X    f= popen ("lpr -Plw", "w");
  2854. X    if (f == (FILE *) NULL) {
  2855. X        StatusMsg ("popen: Couldn't find laser printer (lpr -Plw).\n");
  2856. X        return 1;
  2857. X    }
  2858. X    fprintf (f, "%%!\n");    /* Tell lpr to pass commands to postscript. */
  2859. X    fprintf (f
  2860. X     , "/cshow { dup stringwidth exch 2 div neg exch rmoveto show } def\n");
  2861. X    fprintf (f, "(Times-Roman) findfont %d scalefont setfont\n", FontPts);
  2862. X    for (i= 0; i < Game->Grid; i++) {
  2863. X        fprintf (f, "%d %d moveto %d %d lineto stroke\n"
  2864. X        , BrdMargin + i * Diam, BrdMargin
  2865. X        , BrdMargin + i * Diam, BrdMargin + LastLine * Diam);
  2866. X        fprintf (f, "%d %d moveto %d %d lineto stroke\n"
  2867. X        , BrdMargin, BrdMargin + i * Diam
  2868. X        , BrdMargin + LastLine * Diam, BrdMargin + i * Diam);
  2869. X        fprintf (f, "%d %d moveto (%c) show\n"
  2870. X        , BrdMargin + i * Diam - FontPts / 2, Margin
  2871. X        , (i < 8) ? ('A' + i) : ('B' + i));
  2872. X        fprintf (f, "%d %d moveto (%c) show\n"
  2873. X        , BrdMargin + i * Diam - FontPts / 2
  2874. X        , PageWidth - Margin
  2875. X        , (i < 8) ? ('A' + i) : ('B' + i));
  2876. X        fprintf (f, "%d %d moveto (%d) show\n"
  2877. X        , Margin, BrdMargin + i * Diam - FontPts / 2, i + 1);
  2878. X        fprintf (f, "%d %d moveto (%d) show\n", PageWidth - Margin
  2879. X        , BrdMargin + i * Diam - FontPts / 2, i + 1);
  2880. X    }
  2881. X    if (Game->Grid == 19) {
  2882. X        for (i= 0; i < 3; i++) {
  2883. X        for (j= 0; j < 3; j++) {
  2884. X            fprintf (f, "newpath %d %d %d 0 360 arc fill\n"
  2885. X            , BrdMargin + (3 + i * 6) * Diam
  2886. X            , BrdMargin + (3 + j * 6) * Diam, 3);
  2887. X        }
  2888. X        }
  2889. X    }
  2890. X    fprintf (f, "newpath\n");
  2891. X    for (i= 0; i < Game->Grid; i++) {
  2892. X        for (j= 0; j < Game->Grid; j++) {
  2893. X        if (Game->InitialBoard [i][j] != Empty) {
  2894. X            fprintf (f, "%d %d %d 0 360 arc fill\n", BrdMargin + i *Diam
  2895. X            , BrdMargin + j * Diam, Diam / 2 - Units / 72);
  2896. X            if (Game->InitialBoard [i][j] == White) {
  2897. X            fprintf (f, "1 setgray %d %d %d 0 360 arc fill\n"
  2898. X                , BrdMargin + i * Diam, BrdMargin + j * Diam
  2899. X                , Diam / 2 - Units / 36);
  2900. X            fprintf (f, "0 setgray\n");
  2901. X            }
  2902. X        }
  2903. X        }
  2904. X    }
  2905. X    if (Game->MoveNum < 10) FontPts= 12;
  2906. X    else if (Game->MoveNum < 100) FontPts= 10;
  2907. X    else FontPts= 8;
  2908. X    fprintf (f, "(Times-Roman) findfont %d scalefont setfont\n", FontPts);
  2909. X    FontPts= FontPts / 3;
  2910. X    s= Game->FirstPlayer;
  2911. X    for (k= 0, Move= Game->MoveList; (k < Game->MoveNum) && (Move!=NULL)
  2912. X        ; k++){
  2913. X        i= Move->i;
  2914. X        j= Move->j;
  2915. X        if (i >= 0) {
  2916. X        if (Game->Board [i] [j] == Empty) {
  2917. X            fprintf (f, "newpath 1 setgray %d %d %d 0 360 arc fill\n"
  2918. X            , BrdMargin + i * Diam, BrdMargin + j * Diam
  2919. X            , Diam / 2 - Units / 36);
  2920. X            fprintf (f, "0 setgray\n");
  2921. X            fprintf (f, "%d %d moveto (%d) cshow\n"
  2922. X            , BrdMargin + i * Diam, BrdMargin + j * Diam - FontPts
  2923. X            , k + 1);
  2924. X        } else {
  2925. X            fprintf (f, "newpath %d %d %d 0 360 arc fill\n"
  2926. X            , BrdMargin + i * Diam, BrdMargin + j * Diam
  2927. X            , Diam / 2 - Units / 72);
  2928. X            if (Game->Board [i] [j] == White) {
  2929. X            fprintf (f, "1 setgray %d %d %d 0 360 arc fill\n"
  2930. X                , BrdMargin + i * Diam, BrdMargin + j * Diam
  2931. X                , Diam / 2 - Units / 36);
  2932. X            fprintf (f, "0 setgray\n");
  2933. X            fprintf (f, "%d %d moveto (%d) cshow\n"
  2934. X                , BrdMargin + i * Diam
  2935. X                , BrdMargin + j * Diam - FontPts
  2936. X                , k + 1);
  2937. X            } else {
  2938. X            fprintf (f, "1 setgray %d %d moveto (%d) cshow\n"
  2939. X                , BrdMargin + i * Diam
  2940. X                , BrdMargin + j * Diam - FontPts
  2941. X                , k + 1);
  2942. X            fprintf (f, "0 setgray\n");
  2943. X            }
  2944. X        }
  2945. X        }
  2946. X        s= !s;
  2947. X        Move= Move->Next;
  2948. X    }
  2949. X    }
  2950. X    fprintf (f, "(Times-Roman) findfont %d scalefont setfont\n", 18);
  2951. X    fprintf (f, "%d %d moveto (%s) show\n", Margin, PageWidth + Margin
  2952. X    , Game->Title);
  2953. X    if (Game->MoveNum & 1) s= !Game->FirstPlayer;
  2954. X    else s= Game->FirstPlayer;
  2955. X    fprintf (f, "%d %d moveto (%s to move.) show\n"
  2956. X    , Margin, PageWidth + Margin/2, (s == Black) ? "Black" : "White");
  2957. X    fprintf (f, "%d %d moveto\n", Margin, PageWidth);
  2958. X    fprintf (f, "(White stones captured:  %d,  Black stones captured:  %d.)"
  2959. X    , Game->Prisoners [White], Game->Prisoners [Black]);
  2960. X    fprintf (f, " show\n");
  2961. X    fprintf (f, "showpage\n");    /* Tell postscript to print. */
  2962. X#ifdef DEBUG
  2963. X#else
  2964. X    pclose (f);
  2965. X#endif
  2966. X    return 0;
  2967. X} /* PrintBoard */
  2968. X
  2969. X
  2970. XSigPipe ()
  2971. X/* Take care of broken pipe from lpr -Plw. */
  2972. X{
  2973. X    longjmp (LWEnvironment, 1);
  2974. X} /* SigPipe */
  2975. END_OF_FILE
  2976. if test 5030 -ne `wc -c <'goprint.c'`; then
  2977.     echo shar: \"'goprint.c'\" unpacked with wrong size!
  2978. fi
  2979. # end of 'goprint.c'
  2980. fi
  2981. if test -f 'goservice.c' -a "${1}" != "-c" ; then 
  2982.   echo shar: Will not clobber existing file \"'goservice.c'\"
  2983. else
  2984. echo shar: Extracting \"'goservice.c'\" \(16823 characters\)
  2985. sed "s/^X//" >'goservice.c' <<'END_OF_FILE'
  2986. X#ifndef lint
  2987. Xstatic char sccsid[]= "@(#)goservice.c 1.3 87/01/11 Copyr 1986 Sun Micro";
  2988. X#endif
  2989. X
  2990. X/* Copyright (c) Sun MicroSystems, 1986.  This code may be used and modified
  2991. X    for not-for-profit use.  This notice must be retained.  */
  2992. X
  2993. X#include "goban.h"
  2994. X#include <suntool/panel.h>
  2995. X
  2996. XMoveType    *TrashMoves;
  2997. XCaptureType    *TrashCaptures;
  2998. XGroupType    *TrashGroups;
  2999. X
  3000. Xextern Panel_item    CurrMoveSlider, HandicapSlider, NameButton;
  3001. X
  3002. X
  3003. X    CaptureType *
  3004. XAllocCapture (i, j)
  3005. X    int i, j;
  3006. X{
  3007. XCaptureType *c;
  3008. X    if (TrashCaptures != NULL) {
  3009. X    c= TrashCaptures;
  3010. X    TrashCaptures= TrashCaptures->Next;
  3011. X    } else {
  3012. X    c= Malloc (CaptureType);
  3013. X    }
  3014. X    c->Next= NULL;
  3015. X    c->i= i;
  3016. X    c->j= j;
  3017. X    return c;
  3018. X} /* AllocCapture */
  3019. X
  3020. X
  3021. X    GroupType *
  3022. XAllocGroup (Color, Libs, NumStones)
  3023. X    int Color, Libs, NumStones;
  3024. X{
  3025. XGroupType *g;
  3026. X    if (TrashGroups != NULL) {
  3027. X    g= TrashGroups;
  3028. X    TrashGroups= TrashGroups->Next;
  3029. X    } else {
  3030. X    g= Malloc (GroupType);
  3031. X    }
  3032. X    g->Color= Color;
  3033. X    g->NumLibs= Libs;
  3034. X    g->NumStones= NumStones;
  3035. X    g->Next= NULL;
  3036. X    return g;
  3037. X} /* AllocGroup */
  3038. X
  3039. X
  3040. X    MoveType *
  3041. XAllocMove (i, j, CurrMove)
  3042. X    int i, j;
  3043. X    MoveType *CurrMove;
  3044. X{
  3045. XMoveType *m;
  3046. X    if (TrashMoves != NULL) {
  3047. X    m= TrashMoves;
  3048. X    TrashMoves= TrashMoves->Next;
  3049. X    } else {
  3050. X    m= Malloc (MoveType);
  3051. X    }
  3052. X    m->Next= NULL;
  3053. X    m->Prev= CurrMove;
  3054. X    m->AltNext= m;
  3055. X    m->AltPrev= m;
  3056. X    m->Label [0]= ' ';
  3057. X    m->Label [1]= '\0';
  3058. X    m->Note= NULL;
  3059. X    if (CurrMove != NULL) CurrMove->Next= m;
  3060. X    m->Captures= NULL;
  3061. X    m->i= i;
  3062. X    m->j= j;
  3063. X    return m;
  3064. X} /* AllocMove */
  3065. X
  3066. X
  3067. XCafard (s)    /* French for cockroach */
  3068. X    char *s;
  3069. X{
  3070. X    fprintf (stderr, s);
  3071. X    exit (1);
  3072. X} /* Cafard */
  3073. X
  3074. X
  3075. XFreeCaptures (c)
  3076. X    CaptureType *c;
  3077. X/* Free capture c and all succeeding captures in its list by moving into
  3078. X    TrashCaptures.
  3079. X*/
  3080. X{
  3081. XCaptureType *c1;
  3082. X    if (c == NULL) return;
  3083. X    for (c1= c; c->Next != NULL; c= c->Next);    /* Go to end of list. */
  3084. X    c->Next= TrashCaptures;
  3085. X    TrashCaptures= c1;
  3086. X} /* FreeCaptures */
  3087. X
  3088. X
  3089. XFreeGroup (g)
  3090. X    GroupType *g;
  3091. X{
  3092. XGroupType *t;
  3093. X    if (g == NULL) return;
  3094. X    for (t= TrashGroups; t != NULL; t= t->Next)
  3095. X    if (g == t) return;
  3096. X    g->Next= TrashGroups;
  3097. X    TrashGroups= g;
  3098. X} /* FreeGroup */
  3099. X
  3100. X
  3101. XFreeMoves (m)
  3102. X    MoveType *m;
  3103. X/* Free move m and all succeeding moves in its list by moving into TrashMoves.
  3104. X    Trim off and free all side trees descending from m.
  3105. X*/
  3106. X{
  3107. XMoveType *m1, *m2;
  3108. X    if (m == NULL) return;
  3109. X    FreeCaptures (m->Captures);
  3110. X    if (m->Note != NULL) {
  3111. X    free (m->Note);
  3112. X    m->Note= NULL;
  3113. X    }
  3114. X    for (m1= m->Next; m1 != NULL; m1= m2) {
  3115. X    m2= m1->AltNext;
  3116. X    FreeMoves (m1);
  3117. X    if (m1->AltPrev != NULL) m1->AltPrev->AltNext= NULL;
  3118. X    if (m1->AltNext != NULL) m1->AltNext->AltPrev= NULL;
  3119. X    if (m2 == m->Next) break;
  3120. X    }
  3121. X    m->Next= TrashMoves;
  3122. X    TrashMoves= m;
  3123. X} /* FreeMoves */
  3124. X
  3125. X
  3126. XGetComment (F, String,     ReturnedString)
  3127. X    FILE    *F;
  3128. X    char    *String, **ReturnedString;
  3129. X{
  3130. X#define MaxBuf    1024
  3131. Xint    NumChars, Quit;
  3132. Xchar    Buf [MaxBuf], *s, *b;
  3133. X    s= String + 2;
  3134. X    while (*s == ' ') s++;
  3135. X    b= Buf;
  3136. X    Buf [0]= '\0';
  3137. X    Quit= 0;
  3138. X    while (*s != '\0') {
  3139. X    if ((*s == '*') && (*(s+1) == '/')) {
  3140. X        *b++= '\0';
  3141. X        Quit= 1;
  3142. X        break;
  3143. X    }
  3144. X    *b++= *s++;
  3145. X    }
  3146. X    if (!Quit) {
  3147. X    while ((b - Buf) < MaxBuf) {
  3148. X        *b= getc (F);
  3149. X        if (*b == '/') {
  3150. X        if (*(b-1) == '*') {
  3151. X            *(b-1)= '\0';
  3152. X            b--;
  3153. X            break;
  3154. X        }
  3155. X        }
  3156. X        b++;
  3157. X    }
  3158. X    }
  3159. X    while ((b >= Buf) && (*b == ' ')) {
  3160. X    *b--= '\0';
  3161. X    }
  3162. X    if (Buf [0] != '\0') {
  3163. X    NumChars= b- Buf;
  3164. X    s= *ReturnedString= (char *) malloc (NumChars + 1);
  3165. X    for (b= Buf; NumChars > 0; NumChars--) *s++= *b++;
  3166. X    *s= '\0';
  3167. X    }
  3168. X    if (EOF == fscanf (F, "%s", String)) return 1;
  3169. X    else return 0;
  3170. X#undef MaxBuf
  3171. X} /* GetComment */
  3172. X
  3173. X
  3174. XHandicapBoard (Game)
  3175. X    GameType *Game;
  3176. X/* Set Handicap points on board to black. */
  3177. X{
  3178. Xint i, j;
  3179. X    switch (Game->Handicap) {
  3180. X    default:  printf ("Handicap (%d) larger than 17.\n", Game->Handicap);
  3181. X    Game->Handicap= 17;
  3182. X    case 17:  Game->InitialBoard [ 6] [12]= Black;
  3183. X    case 16:  Game->InitialBoard [12] [ 6]= Black;
  3184. X    case 15:  Game->InitialBoard [ 6] [ 6]= Black;
  3185. X    case 14:  Game->InitialBoard [12] [12]= Black;
  3186. X    case 13:  Game->InitialBoard [ 2] [16]= Black;
  3187. X    case 12:  Game->InitialBoard [16] [ 2]= Black;
  3188. X    case 11:  Game->InitialBoard [ 2] [ 2]= Black;
  3189. X    case 10:  Game->InitialBoard [16] [16]= Black;
  3190. X    case 9:   Game->InitialBoard [ 9] [ 9]= Black;
  3191. X    case 8:   Game->InitialBoard [ 9] [15]= Black;
  3192. X    case 7:  if (Game->Handicap == 7) Game->InitialBoard [9] [9]= Black;
  3193. X        else Game->InitialBoard [9] [3]= Black;
  3194. X    case 6:  Game->InitialBoard [3] [9]= Black;
  3195. X    case 5:  if (Game->Handicap == 5) Game->InitialBoard [9] [9]= Black;
  3196. X        else Game->InitialBoard [15] [9]= Black;
  3197. X    case 4:  Game->InitialBoard [ 3] [15]= Black;
  3198. X    case 3:  Game->InitialBoard [15] [ 3]= Black;
  3199. X    case 2:  Game->InitialBoard [ 3] [ 3]= Black;
  3200. X    case 1:  Game->InitialBoard [15] [15]= Black;
  3201. X    case 0:  break;
  3202. X    } /*switch*/
  3203. X    for (i= 0; i < MaxGrid; i++)
  3204. X    for (j= 0; j < MaxGrid; j++) {
  3205. X        Game->Board [i] [j]= Game->InitialBoard [i] [j];
  3206. X        if (Game->InitialBoard [i] [j] != Empty) {
  3207. X        if (Game->Groups [i][j] != NULL)
  3208. X            FreeGroup (Game->Groups [i][j]);
  3209. X        Game->Groups [i] [j]=
  3210. X            AllocGroup (Game->InitialBoard [i] [j], 4, 1);
  3211. X        }
  3212. X    }
  3213. X} /* HandicapBoard */
  3214. X
  3215. X
  3216. X    char *
  3217. XPositionToString (i, j, String, Depth)
  3218. X    int i, j;
  3219. X    char String [];
  3220. X    int Depth;    /* level of tree. */
  3221. X/* Write into a char array a string consisting of
  3222. X    <depth>."pass" or
  3223. X    <depth>.<letter><one or two digits><newline>.
  3224. X    If Depth == 0 ignore it.
  3225. X*/
  3226. X{
  3227. X    if (Depth == 0) {
  3228. X    if (i >= 0)
  3229. X        sprintf (String, "%c%d", 'A' + ((i > 7) ? (i + 1) : i), j + 1);
  3230. X    else sprintf (String, "%s", "pass");
  3231. X    } else {
  3232. X    if (i >= 0)
  3233. X        sprintf (String, "%d.%c%d"
  3234. X        , Depth, 'A' + ((i > 7) ? (i + 1) : i), j + 1);
  3235. X    else sprintf (String, "%d.%s", Depth, "pass");
  3236. X    }
  3237. X    return String;
  3238. X} /* PositionToString */
  3239. X
  3240. X
  3241. XReadGame (GameName, Game, ShouldPaint)
  3242. X    char *GameName;
  3243. X    GameType *Game;
  3244. X    Panel_setting ShouldPaint;
  3245. X{
  3246. XFILE *F;
  3247. Xint        i, j, NumCaptures, Depth;
  3248. Xchar        String [40];
  3249. Xchar        Err [80];
  3250. XStone        Color;
  3251. XMoveType    *Move, *m;
  3252. X    if (NULL == (F= fopen (GameName, "r", 0))) return 1;
  3253. X    ZeroGame (Game, ShouldPaint);
  3254. X    strncpy (Game->Title, GameName, MaxTitleChars-1);
  3255. X    fscanf (F, "%s", String);    /* Size of board. */
  3256. X    if ((String [0] == '/') && (String [1] == '*')) {
  3257. X    GetComment (F, String, &(Game->Note));
  3258. X    }
  3259. X    Game->Grid= atoi (String);
  3260. X    fscanf (F, "%s", String);    /* Handicap. */
  3261. X    Game->Handicap= atoi (String);
  3262. X    if (Game->Handicap == 0) {    /* Initial board position from file. */
  3263. X    for (;;) {
  3264. X        fscanf (F, "%s", String);
  3265. X        if (String [0] == '.') break;
  3266. X        StringToPosition (String, &i, &j, &Depth);
  3267. X        Game->InitialBoard [i] [j]= Black;
  3268. X    }
  3269. X    for (;;) {
  3270. X        fscanf (F, "%s", String);
  3271. X        if (String [0] == '.') break;
  3272. X        StringToPosition (String, &i, &j, &Depth);
  3273. X        Game->InitialBoard [i] [j]= White;
  3274. X    }
  3275. X    for (i= 0; i < Game->Grid; i++)
  3276. X        for (j= 0; j < Game->Grid; j++) {
  3277. X        Game->Board [i] [j]= Game->InitialBoard [i] [j];
  3278. X        }
  3279. X    } else {    /* Initial board position automatic. */
  3280. X    HandicapBoard (Game);
  3281. X    }
  3282. X    if (EOF == fscanf (F, "%s", String))
  3283. X    Cafard ("Unexpected end of file after handicap or initial board.\n");
  3284. X    if (String [0] == 'B') Game->FirstPlayer= Black;
  3285. X    else if (String [0] == 'W') Game->FirstPlayer= White;
  3286. X    for (Game->MoveNum= 0; ;) {
  3287. X    if (EOF == fscanf (F, "%s", String)) break;
  3288. X    if (String [0] == '|') {
  3289. X        SetLabel (Move, String + 1);
  3290. X        if (EOF == fscanf (F, "%s", String)) break;
  3291. X    }
  3292. X    if ((String [0] == '/') && (String [1] == '*')) {
  3293. X        if (GetComment (F, String, &(Move->Note))) break;
  3294. X    }
  3295. X    StringToPosition (String, &i, &j, &Depth);
  3296. X    Depth--;
  3297. X    if ((Depth >= 0) && (Game->MoveNum != Depth)) {
  3298. X        if (Depth > Game->MoveNum) {
  3299. X        sprintf (Err,"Moves out of order:  too deep. \"%s\".\n",String);
  3300. X        Cafard (Err);
  3301. X        }
  3302. X        while (Depth < Game->MoveNum) {
  3303. X        Move= Move->Prev;
  3304. X        Backup (Game, 0);
  3305. X        }
  3306. X        /* Install as alternate branch. */
  3307. X        if (Move != NULL) {
  3308. X        m= AllocMove (i, j, (MoveType *) NULL);
  3309. X        m->Prev= Move;
  3310. X        m->AltPrev= Move->Next->AltPrev;
  3311. X        Move->Next->AltPrev= m;
  3312. X        m->AltNext= Move->Next;
  3313. X        m->AltPrev->AltNext= m;
  3314. X        Move= m;
  3315. X        } else {
  3316. X        m= AllocMove (i, j, (MoveType *) NULL);
  3317. X        m->AltNext= Game->MoveList;
  3318. X        m->AltPrev= Game->MoveList->AltPrev;
  3319. X        m->AltPrev->AltNext= m;
  3320. X        Game->MoveList->AltPrev= m;
  3321. X        Move= m;
  3322. X        }
  3323. X    } else {
  3324. X        if (Game->MoveList == NULL) {
  3325. X        Game->MoveList= Move= AllocMove (i, j, (MoveType *) NULL);
  3326. X        } else {
  3327. X        Move->Next= AllocMove (i, j, Move);
  3328. X        Move= Move->Next;
  3329. X        }
  3330. X    }
  3331. X    Game->CurrMove= Move;
  3332. X    if (i >= 0) {
  3333. X        Game->Board [i] [j]= Color=
  3334. X        (Game->MoveNum & 1) ? !Game->FirstPlayer : Game->FirstPlayer;
  3335. X        NewStoneToGroups (Game, i, j);
  3336. X        NumCaptures= GenCaptures (Game, !Color, Move);
  3337. X    }
  3338. X    if (++Game->MoveNum > Game->NumMoves) Game->NumMoves= Game->MoveNum;
  3339. X    }
  3340. X    for (Move= Game->MoveList, Game->MoveNum= 0; Move != NULL; Move=Move->Next){
  3341. X    Game->MoveNum++;
  3342. X    }
  3343. X    Color= (Game->MoveNum & 1) ? !Game->FirstPlayer : Game->FirstPlayer;
  3344. X    SetFirstPlayerButton (Color, ShouldPaint);
  3345. X    panel_set (CurrMoveSlider
  3346. X    , PANEL_MAX_VALUE, Game->NumMoves
  3347. X    , PANEL_VALUE, Game->MoveNum
  3348. X    , PANEL_PAINT, ShouldPaint, 0);
  3349. X    panel_set (HandicapSlider, PANEL_VALUE, Game->Handicap
  3350. X    , PANEL_PAINT, ShouldPaint, 0);
  3351. X    if (Game->MoveList != NULL) Game->CurrMove= Move;
  3352. X    return 0;
  3353. X} /* ReadGame */
  3354. X
  3355. X
  3356. XSetFirst (Game, s, ShouldPaint)
  3357. X    GameType *Game;
  3358. X    Stone s;
  3359. X    Panel_setting ShouldPaint;
  3360. X/* Set first player of game. */
  3361. X{
  3362. X    Game->FirstPlayer= s;
  3363. X    SetFirstPlayerButton (s, ShouldPaint);
  3364. X} /* SetFirst */
  3365. X
  3366. X
  3367. XSetLabel (m, s)
  3368. X    MoveType    *m;
  3369. X    char    *s;
  3370. X{
  3371. X    m->Label [0]= *s;
  3372. X    m->Label [1]= '\0';
  3373. X} /* SetLabel */
  3374. X
  3375. X
  3376. X
  3377. XStringToPosition (String, i, j, Depth)
  3378. X    char String [];
  3379. X    int *i, *j, *Depth;
  3380. X/* Parses string of form <letter><one or two digits> and leaves
  3381. X     corresponding position in i and j.  The string may be prepended
  3382. X     with <depth><period>.
  3383. X */
  3384. X{
  3385. Xchar Err [80];
  3386. Xchar *s;
  3387. X    *Depth= 0;
  3388. X    *i= -1;
  3389. X    *j= -1;
  3390. X    s= String;
  3391. X    if ((*s >= '0') && (*s <= '9')) {
  3392. X    while ((*s >= '0') && (*s <= '9')) { /* Initial depth? */
  3393. X        *Depth= *Depth * 10 + *s++ - '0';
  3394. X    }
  3395. X    if (*s++ != '.') *Depth= -1;    /* Alert error routine. */
  3396. X    }
  3397. X    if ((0 == strncmp (s, "pass", 4)) && (*(s + 4) == '\0')) {
  3398. X    return 0;    /* OK */
  3399. X    }
  3400. X    if (*s > 'I') (*s)--;
  3401. X    *i= *s - 'A';
  3402. X    if (*(s+2) != '\0') *j= 10 + *(s+2) - '1';
  3403. X    else *j= *(s+1) - '1';
  3404. X    if ((*Depth<0) || (*i<0) || (*i >=MaxGrid) || (*j < 0) || (*j >= MaxGrid)) {
  3405. X    sprintf (Err, "Bad position %s (%d %d %d).\n", String, *i, *j, *Depth);
  3406. X    Cafard (Err);
  3407. X    }
  3408. X} /* StringToPosition */
  3409. X
  3410. X
  3411. XWriteBoard (GameName, Game)
  3412. X    char *GameName;
  3413. X    GameType *Game;
  3414. X{
  3415. XFILE *F;
  3416. Xint i, j, k, Count, MoveNum, NumRows;
  3417. XMoveType *m;
  3418. Xchar String [80];
  3419. Xchar Moves [MaxMoves] [2];
  3420. X    sprintf (String, "%s.brd", GameName);
  3421. X    if (NULL == (F= fopen (String, "w", 0))) return 1;
  3422. X    if (Game->Handicap != 0) fprintf (F, "Handicap:  %d.\n", Game->Handicap);
  3423. X    for (i= 0, Count= 0; i < Game->Grid; i++)
  3424. X    for (j= 0; j < Game->Grid; j++)
  3425. X        if (Game->InitialBoard [i] [j] != Empty) Count++;
  3426. X    if (Count > 0) {
  3427. X    fprintf (F, "Black at:  ");
  3428. X    for (i= 0; i < Game->Grid; i++)
  3429. X        for (j= 0; j < Game->Grid; j++) {
  3430. X        if (Game->InitialBoard [i] [j] == Black) {
  3431. X            fprintf (F, " %s", PositionToString (i, j, String, 0));
  3432. X        } /*if*/
  3433. X        }
  3434. X    fprintf (F, ".\nWhite at:  ");
  3435. X    for (i= 0; i < Game->Grid; i++)
  3436. X        for (j= 0; j < Game->Grid; j++) {
  3437. X        if (Game->InitialBoard [i] [j] == White) {
  3438. X            fprintf (F, " %s", PositionToString (i, j, String, 0));
  3439. X        } /*if*/
  3440. X        }
  3441. X    fprintf (F, ".\n");
  3442. X    }
  3443. X    MoveNum= 0;
  3444. X    m= Game->MoveList;
  3445. X    fprintf (F, "   A B C D E F G H J K L M N O P Q R S T");
  3446. X    if ((Game->FirstPlayer == White) && (m != NULL)) {
  3447. X    fprintf (F, "\t  1:\t\t%s.\n", PositionToString (m->i, m->j, String,0));
  3448. X    MoveNum= 1;
  3449. X    m= m->Next;
  3450. X    } else {
  3451. X    fprintf (F, "\n");
  3452. X    }
  3453. X    for (j= Game->Grid - 1; j >= 0; j--) {
  3454. X    fprintf (F, "%2d", j + 1);
  3455. X    for (i= 0; i < Game->Grid; i++) {
  3456. X        switch (Game->Board [i] [j]) {
  3457. X        case Empty:
  3458. X        if (((i == 3) || (i == (Game->Grid-4)) || (i == (Game->Grid/2)))
  3459. X        && ((j == 3) || (j == (Game->Grid-4)) || (j == (Game->Grid/2))))
  3460. X            fprintf (F, " +");
  3461. X        else fprintf (F, " .");
  3462. X        break;
  3463. X        case Black:  fprintf (F, " *"); break;
  3464. X        case White:  fprintf (F, " O"); break;
  3465. X        }
  3466. X    }
  3467. X    fprintf (F, " %2d", j + 1);
  3468. X    if (m == NULL) fprintf (F, "\n");
  3469. X    else if (MoveNum < Game->MoveNum) {
  3470. X        fprintf (F, "\t%3d:\t%s", MoveNum+1
  3471. X        , PositionToString (m->i, m->j, String, 0));
  3472. X        m= m->Next;
  3473. X        if ((++MoveNum < Game->MoveNum) && (m != NULL)) {
  3474. X        fprintf (F, "\t%s.\n", PositionToString (m->i, m->j, String,0));
  3475. X        m= m->Next;
  3476. X        } else {
  3477. X        fprintf (F, "\n");
  3478. X        }
  3479. X        MoveNum++;
  3480. X    } else {
  3481. X        fprintf (F, "\n");
  3482. X    }
  3483. X    }
  3484. X    fprintf (F, "   A B C D E F G H J K L M N O P Q R S T");
  3485. X    if (m == NULL) fprintf (F, "\n");
  3486. X    else if (MoveNum < Game->MoveNum) {
  3487. X    fprintf (F, "\t%3d:\t%s", MoveNum+1
  3488. X        , PositionToString (m->i, m->j, String, 0));
  3489. X    m= m->Next;
  3490. X    if ((++MoveNum < Game->MoveNum) && (m != NULL))
  3491. X        fprintf (F, "\t%s.\n\n", PositionToString (m->i, m->j, String, 0));
  3492. X    else {
  3493. X        fprintf (F, "\n");
  3494. X    }
  3495. X    if (m != NULL) {
  3496. X        m= m->Next;
  3497. X        MoveNum++;
  3498. X    }
  3499. X    }
  3500. X    for (; MoveNum < Game->MoveNum; MoveNum++) {
  3501. X    if (m == NULL) break;
  3502. X    Moves [MoveNum-40] [0]= (char) m->i;
  3503. X    Moves [MoveNum-40] [1]= (char) m->j;
  3504. X    m= m->Next;
  3505. X    }
  3506. X    NumRows= 1 + ((Game->MoveNum - 41) / 6);
  3507. X    for (i= 0, j= NumRows * 2, k= NumRows * 4; i < NumRows - 1; i++) {
  3508. X    fprintf (F, "%3d:  %3s  %3s\t\t%3d:  %3s  %3s\t\t%3d:  %3s  %3s\n",
  3509. X        i + 41,
  3510. X        PositionToString (Moves [i] [0],   Moves [i] [1],   String, 0),
  3511. X        PositionToString (Moves [i+1] [0], Moves [i+1] [1], String, 0),
  3512. X        j + 41,
  3513. X        PositionToString (Moves [j] [0],   Moves [j] [1],   String, 0),
  3514. X        PositionToString (Moves [j+1] [0], Moves [j+1] [1], String, 0),
  3515. X        k + 41,
  3516. X        PositionToString (Moves [k] [0],   Moves [k] [1],   String, 0),
  3517. X        PositionToString (Moves [k+1] [0], Moves [k+1] [1], String, 0));
  3518. X    }
  3519. X    fprintf ("\n");
  3520. X    fprintf (F, "\nWhite stones captured:  %d.  Black:  %d.\n"
  3521. X    , Game->Prisoners [White], Game->Prisoners [Black]);
  3522. X    fclose (F);
  3523. X    return 0;
  3524. X} /* WriteBoard */
  3525. X
  3526. X
  3527. XWriteGame (GameName, Game)
  3528. X    char    *GameName;
  3529. X    GameType    *Game;
  3530. X{
  3531. XFILE    *F;
  3532. Xint    i, j;
  3533. Xchar    String [80];
  3534. XMoveType *m;
  3535. X    if (NULL == (F= fopen (GameName, "w", 0))) return 1;
  3536. X    if (Game->Note) {
  3537. X    fprintf (F, "/*%s*/\n", Game->Note);
  3538. X    }
  3539. X    fprintf (F, "%d\n", Game->Grid);
  3540. X    fprintf (F, "%d\n", Game->Handicap);    /* Handicap */
  3541. X    if (Game->Handicap == 0) {
  3542. X    for (i= 0; i < Game->Grid; i++)
  3543. X        for (j= 0; j < Game->Grid; j++) {
  3544. X        if (Game->InitialBoard [i] [j] == Black) {
  3545. X            fprintf (F, " %s", PositionToString (i, j, String, 0));
  3546. X        } /*if*/
  3547. X        }
  3548. X    fprintf (F, " .\n");
  3549. X    for (i= 0; i < Game->Grid; i++)
  3550. X        for (j= 0; j < Game->Grid; j++) {
  3551. X        if (Game->InitialBoard [i] [j] == White) {
  3552. X            fprintf (F, " %s", PositionToString (i, j, String, 0));
  3553. X        } /*if*/
  3554. X        }
  3555. X    fprintf (F, " .\n");
  3556. X    } /* else Initial board position automatic. */
  3557. X    if (Game->FirstPlayer == Black) fprintf (F, "Black\n");
  3558. X    else fprintf (F, "White\n");
  3559. X    for (m= Game->MoveList; m != NULL; m= m->AltNext) {
  3560. X    WriteBranch (m, 1, F);
  3561. X    if (m->AltNext == Game->MoveList) break;
  3562. X    }
  3563. X    fprintf (F, "\n");
  3564. X    fclose (F);
  3565. X    return 0;
  3566. X} /* WriteGame */
  3567. X
  3568. X
  3569. XWriteBranch (m, Depth, F)
  3570. X    MoveType    *m;
  3571. X    int        Depth;
  3572. X    FILE    *F;
  3573. X{
  3574. XMoveType *m1;
  3575. Xchar    String [20];
  3576. X    fprintf (F, "%s\n", PositionToString (m->i, m->j, String, Depth));
  3577. X    if ((m->Label [0] != ' ') && (m->Label [0] != '\0'))
  3578. X    fprintf (F, "|%s\n", m->Label);
  3579. X    if (m->Note) fprintf (F, "/*%s*/\n", m->Note);
  3580. X    if (m->Next != NULL)
  3581. X    for (m1= m->Next, Depth++; m1 != NULL; m1= m1->AltNext) {
  3582. X        WriteBranch (m1, Depth, F);
  3583. X        if (m1->AltNext == m->Next) break;
  3584. X    }
  3585. X} /* WriteBranch */
  3586. X
  3587. X
  3588. XZeroGame (Game, ShouldPaint)
  3589. X    GameType *Game;
  3590. X    Panel_setting ShouldPaint;
  3591. X/* Initializes a game by clearing boards and data structures. */
  3592. X{
  3593. Xint i, j;
  3594. X    if (Game->Note) free (Game->Note);
  3595. X    for (i= 0; i < MaxGrid; i++)
  3596. X    for (j= 0; j < MaxGrid; j++) {
  3597. X        Game->InitialBoard [i] [j]= Empty;
  3598. X        Game->Groups [i] [j]= NULL;
  3599. X    }
  3600. X    if (Game->MoveList != NULL) FreeMoves (Game->MoveList);
  3601. X    Game->MoveList= Game->CurrMove= NULL;
  3602. X    Game->NumMoves= Game->MoveNum= 0;
  3603. X    panel_set (CurrMoveSlider, PANEL_VALUE, Game->MoveNum
  3604. X    , PANEL_PAINT, ShouldPaint, 0);
  3605. X    if (Game->Handicap == 0) SetFirst (Game, Black, ShouldPaint);
  3606. X    else SetFirst (Game, White, ShouldPaint);
  3607. X    Game->Placing= 0;
  3608. X    Game->Grid= 19;    /* Traditional. */
  3609. X    Game->Prisoners [0]= Game->Prisoners [1]= 0;
  3610. X} /* ZeroGame */
  3611. END_OF_FILE
  3612. if test 16823 -ne `wc -c <'goservice.c'`; then
  3613.     echo shar: \"'goservice.c'\" unpacked with wrong size!
  3614. fi
  3615. # end of 'goservice.c'
  3616. fi
  3617. if test -f 'masterofgo' -a "${1}" != "-c" ; then 
  3618.   echo shar: Will not clobber existing file \"'masterofgo'\"
  3619. else
  3620. echo shar: Extracting \"'masterofgo'\" \(1699 characters\)
  3621. sed "s/^X//" >'masterofgo' <<'END_OF_FILE'
  3622. X19
  3623. X0
  3624. X .
  3625. X .
  3626. XBlack
  3627. X1.R16
  3628. X2.R4
  3629. X3.D3
  3630. X4.C5
  3631. X5.E4
  3632. X6.P16
  3633. X7.P17
  3634. X8.O17
  3635. X9.Q17
  3636. X10.N16
  3637. X11.O15
  3638. X12.P15
  3639. X13.O18
  3640. X14.O14
  3641. X15.N18
  3642. X16.O3
  3643. X17.Q14
  3644. X18.C15
  3645. X19.C17
  3646. X20.E16
  3647. X21.E17
  3648. X22.F17
  3649. X23.F16
  3650. X24.G16
  3651. X25.F15
  3652. X26.E15
  3653. X27.G17
  3654. X28.F18
  3655. X29.E18
  3656. X30.G18
  3657. X31.F14
  3658. X32.H17
  3659. X33.E14
  3660. X34.C16
  3661. X35.B17
  3662. X36.C12
  3663. X37.D11
  3664. X38.C11
  3665. X39.D10
  3666. X40.C10
  3667. X41.D9
  3668. X42.C9
  3669. X43.D8
  3670. X44.C7
  3671. X45.D6
  3672. X46.C6
  3673. X47.D7
  3674. X48.K4
  3675. X49.K17
  3676. X50.K15
  3677. X51.J15
  3678. X52.K16
  3679. X53.J16
  3680. X54.J17
  3681. X55.L17
  3682. X56.J14
  3683. X57.H15
  3684. X58.K14
  3685. X59.H14
  3686. X60.K18
  3687. X61.L18
  3688. X62.J19
  3689. X63.O5
  3690. X64.O4
  3691. X65.M5
  3692. X66.M4
  3693. X67.M15
  3694. X68.M14
  3695. X69.L14
  3696. X70.N15
  3697. X71.M13
  3698. X72.N14
  3699. X73.L16
  3700. X74.L13
  3701. X75.L15
  3702. X76.M12
  3703. X77.K13
  3704. X78.N13
  3705. X79.Q12
  3706. X80.K12
  3707. X81.J13
  3708. X82.R8
  3709. X83.R10
  3710. X84.S10
  3711. X85.S11
  3712. X86.P8
  3713. X87.S9
  3714. X88.L5
  3715. X89.H3
  3716. X90.H4
  3717. X91.G4
  3718. X92.G3
  3719. X93.H2
  3720. X94.J3
  3721. X95.H5
  3722. X96.J4
  3723. X97.G2
  3724. X98.L8
  3725. X99.L11
  3726. X100.L12
  3727. X101.S7
  3728. X102.S8
  3729. X103.T8
  3730. X104.R7
  3731. X105.S6
  3732. X106.R5
  3733. X107.B4
  3734. X108.D13
  3735. X109.B16
  3736. X110.B15
  3737. X111.D17
  3738. X112.G5
  3739. X113.F3
  3740. X114.H6
  3741. X115.P10
  3742. X116.O10
  3743. X117.O11
  3744. X118.N10
  3745. X119.P9
  3746. X120.O9
  3747. X121.H16
  3748. X122.H18
  3749. X123.R6
  3750. X124.Q6
  3751. X125.T4
  3752. X126.S3
  3753. X127.N11
  3754. X128.M11
  3755. X129.O8
  3756. X130.S5
  3757. X131.O7
  3758. X132.P7
  3759. X133.M10
  3760. X134.N9
  3761. X135.M9
  3762. X136.N8
  3763. X137.M8
  3764. X138.N7
  3765. X139.M7
  3766. X140.N6
  3767. X141.M6
  3768. X142.N5
  3769. X143.K10
  3770. X144.J2
  3771. X145.T5
  3772. X146.T3
  3773. X147.T7
  3774. X148.B5
  3775. X149.B3
  3776. X150.J9
  3777. X151.J10
  3778. X152.H10
  3779. X153.J11
  3780. X154.K9
  3781. X155.H8
  3782. X156.H9
  3783. X157.F5
  3784. X158.G6
  3785. X159.G8
  3786. X160.J8
  3787. X161.C8
  3788. X162.B8
  3789. X163.O12
  3790. X164.N12
  3791. X165.R9
  3792. X166.P13
  3793. X167.Q13
  3794. X168.E19
  3795. X169.D19
  3796. X170.F19
  3797. X171.B19
  3798. X172.H7
  3799. X173.J1
  3800. X174.K1
  3801. X175.H1
  3802. X176.K2
  3803. X177.A15
  3804. X178.A14
  3805. X179.A16
  3806. X180.C14
  3807. X181.Q8
  3808. X182.Q7
  3809. X183.Q9
  3810. X184.O6
  3811. X185.F7
  3812. X186.F6
  3813. X187.E6
  3814. X188.A5
  3815. X189.L7
  3816. X190.K7
  3817. X191.F9
  3818. X192.D5
  3819. X193.E5
  3820. X194.H11
  3821. X195.J12
  3822. X196.F10
  3823. X197.D16
  3824. X198.E10
  3825. X199.E9
  3826. X200.D15
  3827. X201.B13
  3828. X202.B14
  3829. X203.C13
  3830. X204.B12
  3831. X205.D14
  3832. X206.A13
  3833. X207.D12
  3834. X208.F12
  3835. X209.E12
  3836. X210.C13
  3837. X211.F11
  3838. X212.G11
  3839. X213.E11
  3840. X214.L9
  3841. X215.L10
  3842. X216.G13
  3843. X217.L19
  3844. X218.K19
  3845. X219.L6
  3846. X220.K6
  3847. X221.G10
  3848. X222.G9
  3849. X223.F10
  3850. X224.G7
  3851. X225.F8
  3852. X226.A4
  3853. X227.A3
  3854. X228.C4
  3855. X229.C3
  3856. X230.P12
  3857. X231.P11
  3858. X232.Q15
  3859. X233.R15
  3860. X234.O16
  3861. X235.T9
  3862. X236.M17
  3863. X237.M18
  3864. X
  3865. END_OF_FILE
  3866. if test 1699 -ne `wc -c <'masterofgo'`; then
  3867.     echo shar: \"'masterofgo'\" unpacked with wrong size!
  3868. fi
  3869. # end of 'masterofgo'
  3870. fi
  3871. if test -f 'masterofgo.brd' -a "${1}" != "-c" ; then 
  3872.   echo shar: Will not clobber existing file \"'masterofgo.brd'\"
  3873. else
  3874. echo shar: Extracting \"'masterofgo.brd'\" \(1 character\)
  3875. sed "s/^X//" >'masterofgo.brd' <<'END_OF_FILE'
  3876. X
  3877. END_OF_FILE
  3878. if test 1 -ne `wc -c <'masterofgo.brd'`; then
  3879.     echo shar: \"'masterofgo.brd'\" unpacked with wrong size!
  3880. fi
  3881. # end of 'masterofgo.brd'
  3882. fi
  3883. echo shar: End of shell archive.
  3884. exit 0
  3885.